当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net Page.Controls对象(找到所有服务器控件)

asp.net Page.Controls对象(找到所有服务器控件)

2018年04月19日  | 移动技术网IT编程  | 我要评论

600字读后感,门头沟歌华有线电话,莫露露未经处理雅照

实例一:
前台
复制代码 代码如下:

<%@ page language="c#" autoeventwireup="true" codefile="default.aspx.cs" inherits="_default" %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div id="div1">
<asp:button id="button1" runat="server" text="button" onclick="button1_click" />
</div>
</form>
</body>
</html>

后台
复制代码 代码如下:

public partial class _default : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{

}
protected void button1_click(object sender, eventargs e)
{
string name = "tree";
//server.transfer("ajax.aspx?id=1&name="+name);
changecontrols();
}
/************controls属性************
* this.controls则包括所有控件。
* system.web.ui.literalcontrol
system.web.ui.htmlcontrols.htmlhead
system.web.ui.literalcontrol
system.web.ui.htmlcontrols.htmlform
system.web.ui.literalcontrol
* 为<div id="div1">加上runat属性,则form.controls里则找不到button1
*/
private void changecontrols()
{
foreach (system.web.ui.control control in this.form.controls)
{
if (control is button)
{
button btn = (button)control;
btn.text = "hello";
}
}
foreach (control control in this.controls)
{
response.write(control.tostring() + "<br/>");
}
}
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网