// .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);
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/z365days/archive/2008/01/05/2026534.aspx
本文介绍在ASP.NET Web应用开发中,如何通过设置TextBox控件的属性使其在被点击时触发特定任务,通常由按钮的OnClick事件完成。通过使用Page.GetPostBackEventReference或ClientScript.GetPostBackEventReference方法,可以实现在不改变页面的情况下执行Button1_Click事件,响应中包括显示当前日期时间。

1169

被折叠的 条评论
为什么被折叠?



