您的位置:首页 > 其它

基本控件的概念和使用

2010-03-30 01:16 453 查看
多个控件公用一个事件处理程序

通过测试sender参数值,可以确定触发事件的具体按钮,如下例:

private void BtnClick(object sender,System.EventArgs e)

{

Button b=(Button)sender;

String buttonID=b.ID;

switch(buttonID)

{

case "btnDoThis":

//DoThis的代码

case "btnDoThat":

//DoThat的代码

}

//所有按钮的通用代码

}

TextBox控件的用法
新建一个TextBoxDemo网站的Default.aspx
<body>
<form id="form1" runat="server">
<div>
<h1>TextBox Demo</h1>
<asp:TextBox ID="txtInput" runat="server" AutoPostBack="true"(自动回发) OnTextChanged="txtInput_TextChanged">
Enter some text
</asp:TextBox>
<br/>
<asp:TextBox ID="txtEcho" runat="server" BackColor="LightGray" ReadOnly="true"/>
</div>
</form>
</body>
|||||||||||||||||||||||||||||||
TextBoxDemo的TextChanged事件处理程序
protected void txtInput_TextChanged(object sender,EventArgs e)
{
txtEcho.Text=txtInput.Text;
}
当更改控件的内容并把光标移出该文本框后,将触发txtInput_TextChanged事件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: