Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text Change event fired when button clicked

Tags:

c#-2.0

I am working on .net 2.0 I am populating a Grid View with multiple textboxes. The textbox has text change event. There is also a button with click event. The problem I am facing is that when the I enter the text in textbox and then click on button, the text change event gets fired, and the execution does not come to button click block. How can I detect if button has been clicked when both the events are fired.

There is the textbox with call to function for text change event

<asp:TextBox ID="txtChassis" runat="server" CssClass="form_text_box" AutoPostBack="true" OnTextChanged="Chassis_TextChanged"></asp:TextBox>

and also call to function for button click event.

<input class="form_button" id="btnSearch" title="Show Details" accesskey="S" type="submit"
                                                                    value="SAVE" name="btnSave" runat="server" onserverclick="btnSearch_ServerClick"/>

However, in case text is placed in textbox and button is clicked, then the text change event function gets called.

like image 780
Rohan Avatar asked Feb 19 '26 22:02

Rohan


1 Answers

Your Problem is, that events in ASP are only raised after a PostBack.
The Post back happens if the Button is pressend, and the Client Posts Back (therfor the Name) his Data of the Fields.
After this PostBack the Server (your application) calls all events that happend during the last Page_Load.
As far as i know, there is no real order in which the events are thrown, but the textChanged event should be thrown anyway.
If you want to hand your textChanged event directly after the Text hast changed you have to use "AutoPostBack" as Myat Thu already mentioned. Be aware that this increases your traffic signifficant, and can also change the flow of your code!
I suggest designen the events indipendet so the user can hit the "PostBack Button" and all events are called at one post back. This saves traffic and load on the server.
But this is just my personal oppinion.

like image 103
oberfreak Avatar answered Feb 21 '26 15:02

oberfreak