Search code examples
asp.netautopostback

Have to click button twice in asp.net (after autopostback textbox)


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?


Solution

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