在進(jìn)行Web應(yīng)用開發(fā)的時(shí)候,,有時(shí)會(huì)需要使點(diǎn)擊文本框控件(TextBox)執(zhí)行某個(gè)特殊的任務(wù),但TextBox卻沒有按鈕那樣的OnClick事件,。百度了一段時(shí)間,,發(fā)現(xiàn)了這個(gè)解決方法,貼于此,,供大家共享,。 // .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); } |
|