电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> C#>>asp.net在页面上动态生成 WebForm控件:

asp.net在页面上动态生成 WebForm控件

来源:网络 | 2013-4-20 | (有1778人读过)

在asp.ne中,我们可以利用程序在编程的时候动态的生成我们需要的WebForms 控件,我们先看看下面的例子 
<html> 
<head> 
<script language="C#" runat="server"> 
void Page_Load(Object sender, EventArgs e) { 
Panel1.Visible=true; 
//生成Label 标签 
Label l = new Label(); 
l.Text = "Label"; 
l.ID = "Label"; 
Panel1.Controls.Add(l); 
Panel1.Controls.Add(new LiteralControl("<br>")); 
//生成 Text 文本输入框 
TextBox t = new TextBox(); 
t.Text = "TextBox"; 
t.ID = "TextBox"; 
Panel1.Controls.Add(t); 
Panel1.Controls.Add(new LiteralControl("<br>")); 
//生成 超联结 文本 并指定 超联结 的 相关属性 
HyperLink h = new HyperLink(); 
h.Text="电脑爱好者"; 
h.NavigateUrl =http://www.cncfan.com; 
Panel1.Controls.Add(h); 
Panel1.Controls.Add(new LiteralControl("<br>")); 


</script> 

</head> 
<body> 
<form runat=server> 

<asp:Panel id="Panel1" runat="server" 
Height="200px" 
Width="300px"> 
</asp:Panel> 
<asp:Button Text="Refresh Panel" runat="server"/> 
</font> 
</form> 

</body> 
</html> 
由此我们可以看出,我们可以 在程序的 具体运行设定的时候给出不同的控件,重要的是这些空间都是动态生成的; 
下面,我给大家 给出 一些 我们常用的 WebForms 控件: 
AdRotator,Button,Calendar,CheckBox,DataGrid,DataList,DropDownList,HyperLink,Image,ImageButton 
Label,Panel,RadioButton,Repeater,Table,TextBox 
这些控件的含义通过他们的名称我们就可以很容易的看出来,所以 我就不在这里详细讲解他们的含义了。
C#热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2023 电脑爱好者 版权所有 备案号:鲁ICP备09059398号