I have a textbox with autopostback=true and a button to save the data in the form.
Functionality works fine when entering a value in the textbox, tabbing out of the textbox and clicking on the save button.
But issue comes up when entering a value in the textbox and directly clicking on the save button without tabbing out of the text box.
In the second scenario, only textchanged event fires and save click event dosen't fire.
What I was expecting was after exection of textchanged event, save click event should also fire. But this is not happening.
This is true, textbox event will fires only in this case, work arround:
1 - you can make the button disabled and then enable it after the text change event fired
2- or you can disable autopostback in the textbox, and when you press the button both of them will be executed
if those suggestions wont help you, please give me more details about the textbox change event, what is the purpose of it, so I will try to think about somthing else.
sdkr_123
Member
5 Points
2 Posts
Text changed event eats button click event
Oct 01, 2009 01:06 PM|LINK
I have a textbox with autopostback=true and a button to save the data in the form.
Functionality works fine when entering a value in the textbox, tabbing out of the textbox and clicking on the save button.
But issue comes up when entering a value in the textbox and directly clicking on the save button without tabbing out of the text box.
In the second scenario, only textchanged event fires and save click event dosen't fire.
What I was expecting was after exection of textchanged event, save click event should also fire. But this is not happening.
Please, suggest me a resolution for this issue.
Thanks.
ASP.NET event handling
AGMAK
Member
326 Points
63 Posts
Re: Text changed event eats button click event
Oct 01, 2009 02:26 PM|LINK
This is true, textbox event will fires only in this case, work arround:
1 - you can make the button disabled and then enable it after the text change event fired
2- or you can disable autopostback in the textbox, and when you press the button both of them will be executed
if those suggestions wont help you, please give me more details about the textbox change event, what is the purpose of it, so I will try to think about somthing else.
Thanks
suthish nair
All-Star
15176 Points
3304 Posts
Re: Text changed event eats button click event
Oct 01, 2009 03:08 PM|LINK
try using javascript:
<asp:TextBox ID="txt1" runat="server" AutoPostBack="true" ontextchanged="txt1_TextChanged" /> <asp:Button ID="btn1" runat="server" Text="Click Me" onclick="btn1_Click" /> <script language="javascript" type="text/javascript"> function Btncall() { document.getElementById("btn1").click(); } function txtFocus() { document.getElementById("txt1").focus(); } </script> <body onload="txtFocus();">protected void btn1_Click(object sender, EventArgs e) { Response.Write(txt1.Text); }leena.d.pati...
Member
430 Points
79 Posts
Re: Text changed event eats button click event
Oct 08, 2009 06:53 AM|LINK
Above solution dosen't work :(
First time it worked, but next time again it is not calling button click event.
Leena
Please remember to mark replies as answers if you find them useful.
leena.d.pati...
Member
430 Points
79 Posts
Re: Text changed event eats button click event
Oct 08, 2009 07:52 AM|LINK
Void textbox1_TextChanged(object sender, EventArgs e)
{
Button1_click(sender, e);
}
Void Button1_click(object sender, EventArgs e)
{
}
Leena
Please remember to mark replies as answers if you find them useful.
suthish nair
All-Star
15176 Points
3304 Posts
Re: Text changed event eats button click event
Oct 08, 2009 08:33 AM|LINK
happy you got it..
yes i cross checked the code.. i forgot to paste it here.
Good luck..
RameshRajend...
Star
7983 Points
2099 Posts
Re: Text changed event eats button click event
Nov 22, 2012 08:02 AM|LINK
http://stackoverflow.com/questions/7552598/text-change-event-fired-when-button-clicked