How to stop text_changed event on a particular button click
-
Hi, There are some text boxes , one "back" and one "reset" button on screen. One text box is employee id. After entering employee id, it populates the rest details in other text boxes. This code is written in text_changed event. it works fine. Issue is with following scenario: Suppose I enter emp id in text box and directly jump to Back button and click it. Now text_changed event take place, rest of details will be populated, we will not go to back page. We will have to reclick back button to go back. Same holds true for reset. So how to avoid this i.e. data should not be populated when we directly jump from text box to back button, should go to back page. same for reset button.
What are you doing to go back to previous page? Could you please provide the code.
Anurag Gandhi. http://www.gandhisoft.com Life is a computer program and every one is the programmer of his own life.
-
What are you doing to go back to previous page? Could you please provide the code.
Anurag Gandhi. http://www.gandhisoft.com Life is a computer program and every one is the programmer of his own life.
I let u know about a simple reproducable code. Drag an asp text box control. Drag an HTML button control. Make the autopost back of textbox=TRUE protected void TextBox2_TextChanged(object sender, EventArgs e) { Response.Write("hi"); } function Button1_onclick() { alert('clicked button'); } Run it. Enter any text in text box and click on button. Button will display "hi", it will not trigger its own event. So I want that on button click, TextBox2_TextChanged event should not take place. IN any other condition, it shold work fine.
-
I let u know about a simple reproducable code. Drag an asp text box control. Drag an HTML button control. Make the autopost back of textbox=TRUE protected void TextBox2_TextChanged(object sender, EventArgs e) { Response.Write("hi"); } function Button1_onclick() { alert('clicked button'); } Run it. Enter any text in text box and click on button. Button will display "hi", it will not trigger its own event. So I want that on button click, TextBox2_TextChanged event should not take place. IN any other condition, it shold work fine.
amittinku wrote:
Drag an asp text box control. Drag an HTML button control.
Well, that sucks. Anyone who uses the designer, is obviously on the wrong track. The designer sucks.
amittinku wrote:
So I want that on button click, TextBox2_TextChanged event should not take place. IN any other condition, it shold work fine.
That sounds like a real bug in ASP.NET. I assume you have other buttons, which would still fire the text changed ? It's a real bug if the text change event on the server, stops the client side onclick from working. Perhaps instead of using OnClientClick, you should use onclick directly ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
amittinku wrote:
Drag an asp text box control. Drag an HTML button control.
Well, that sucks. Anyone who uses the designer, is obviously on the wrong track. The designer sucks.
amittinku wrote:
So I want that on button click, TextBox2_TextChanged event should not take place. IN any other condition, it shold work fine.
That sounds like a real bug in ASP.NET. I assume you have other buttons, which would still fire the text changed ? It's a real bug if the text change event on the server, stops the client side onclick from working. Perhaps instead of using OnClientClick, you should use onclick directly ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Hi Christian, You are right. After entering emp id in text box, if i directly click on any button, textchanged event takes place. So could not get any solution yet how to stop textchanged event if we click on a button. Note:As button is HTML control, so i am using onclick event only.
-
Hi Christian, You are right. After entering emp id in text box, if i directly click on any button, textchanged event takes place. So could not get any solution yet how to stop textchanged event if we click on a button. Note:As button is HTML control, so i am using onclick event only.
-
-
-
Hi, There are some text boxes , one "back" and one "reset" button on screen. One text box is employee id. After entering employee id, it populates the rest details in other text boxes. This code is written in text_changed event. it works fine. Issue is with following scenario: Suppose I enter emp id in text box and directly jump to Back button and click it. Now text_changed event take place, rest of details will be populated, we will not go to back page. We will have to reclick back button to go back. Same holds true for reset. So how to avoid this i.e. data should not be populated when we directly jump from text box to back button, should go to back page. same for reset button.
This happens because in asp textbox if AautoPostBack is set to true, page is posted back when user leaves the control ( here textbox). So basically, when you click the button, first you leave the textbox control and then you click on the button. Hence TextBox' postback the data to server and as the page is reloaded you dont see any alert message. Subsequent click on button shows the alert message. I just replicated your situation.
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<input type="button" id="btnOK" value="OK" onclick="return Button1_onclick();"/><script language="javascript" type="text/javascript">
function Button1_onclick()
{
alert('clicked button');
return false;
}
</script>Thanks, Arindam D Tewary
-
This happens because in asp textbox if AautoPostBack is set to true, page is posted back when user leaves the control ( here textbox). So basically, when you click the button, first you leave the textbox control and then you click on the button. Hence TextBox' postback the data to server and as the page is reloaded you dont see any alert message. Subsequent click on button shows the alert message. I just replicated your situation.
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<input type="button" id="btnOK" value="OK" onclick="return Button1_onclick();"/><script language="javascript" type="text/javascript">
function Button1_onclick()
{
alert('clicked button');
return false;
}
</script>Thanks, Arindam D Tewary
Of course, that's what auto postback means. :doh: I've never used it, so I didn't really think it through, I just assumed that the event fired when he pushes a button to post back.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
This happens because in asp textbox if AautoPostBack is set to true, page is posted back when user leaves the control ( here textbox). So basically, when you click the button, first you leave the textbox control and then you click on the button. Hence TextBox' postback the data to server and as the page is reloaded you dont see any alert message. Subsequent click on button shows the alert message. I just replicated your situation.
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<input type="button" id="btnOK" value="OK" onclick="return Button1_onclick();"/><script language="javascript" type="text/javascript">
function Button1_onclick()
{
alert('clicked button');
return false;
}
</script>Thanks, Arindam D Tewary