首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

textbox 控件怎么添加onclick

2012-01-10 
textbox 控件如何添加onclick ?textbox控件如何添加onclick?点击这个textbox的时候激发服务器端行为?如何

textbox 控件如何添加onclick ?
textbox   控件如何添加onclick   ?  
点击这个textbox的时候激发服务器端行为?如何实现?

[解决办法]
// .aspx
<asp:TextBox ID= "TextBox1 " runat= "server "> </asp:TextBox>
<asp:Button ID= "Button1 " runat= "server " OnClick= "Button1_Click " Text= "我被隐藏啦 " style= "display:none " />

// .aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
// 1.x
// TextBox1.Attributes[ "onclick "] = Page.GetPostBackEventReference(Button1);
// 2.0
TextBox1.Attributes[ "onclick "] = ClientScript.GetPostBackEventReference(Button1, null);
}

protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(DateTime.Now);
}

热点排行