views:

51

answers:

3

On a page I have:

<asp:TextBox runat="server" ID="EmailTextBox" AutoPostBack="true" OnTextChanged="EmailTextBox_Changed" />
<asp:Button runat="server" ID="SearchButton" OnClick="AddButton_Click" Text="add" />

In EmailTextBox_Changed, it counts up how many emails can be found, before running the search.

The problem is, when you type something in EmailTextBox, and click on the button, you have to click twice to get the actual results up. This is because the first click is doing the "AutoPostBack" part from the text box, and then you have to click again to make the actual click postback to happen.

Without removing the "AutoPostBack=true", how can I stop it needing two clicks in these circumstances?

A: 

In fact, you don't have to click on the button to make the first event happen. Just 'leave' the textbox, i.e. with 'tabbing' out of it to make the AutoPostBack happen.

If you want to do both in a single postback just remove the Button and do the things you do in AddButton_Click also in the Textbox_Change event.

Sebastian P.R. Gingter
Hm yes, perhaps. I wanted to try and avoid that as the textbox one only does a count, and the button does a full fetch.
Paul
A: 

You could avoid this by not doing it server side and using Javascript. You also didn't post your page load event. Are you checking if it post back or not ?

Another way you could do this is the event that happens on the click of the button can be called from the TextChanged event and get rid of the button all together.

JonH
Hm yeah, I considered this. There are actually more text boxes, and the autopostback is on there so you can see a count of your results as you filter them down, and when you're ready, you can show them. Maybe a totally javascript solution is the way forward.
Paul
A: 

Making it a client side check was the solution to this...there doesn't seem to be a way to prevent it otherwise

Paul