ASP.NET Button Click is not working on first click when Textbox AutoPostBack is True

1.3k views Asked by At

I have three textbox and one button. Here is my problem:

I use autopostback="true" in textbox, i entered some value and after first click of the button is not working. Then i click again, second click is working. I looked on F12 developer tool on Browser, there is no an error. When i set autopostback="false" than button click is working without any problem.

I would like to use autopostback="true" because it helps me. I think there is a focus problem because when i click out of textbox and than click on the button, button works with autopostback="true"

Do you have any idea for solution of this problem. All controls are working server-side.

<asp:Textbox ID="Name" runat="server" ValidationGroup="myval" AutoPostBack="true"></asp:Textbox>
<asp:Textbox ID="Surname" runat="server" ValidationGroup="myval" AutoPostBack="true"></asp:Textbox>
<asp:Textbox ID="City" runat="server" ValidationGroup="myval" AutoPostBack="true"></asp:Textbox>
<asp:Button ID="send_btn" runat="server Text="Check and Send" OnClick="send_btn_Click" ValidationGroup="myval"></asp:Button>
1

There are 1 answers

0
Hallowen On

I found a solution. It's not stable solution but however it's working. I hope it helps you too. My solution is:

<asp:Button ID="send_btn" runat="server Text="Check and Send" OnClick="send_btn_Click" OnClientClick="return true;" ValidationGroup="myval"></asp:Button>

I added OnClientClick="return true;" and button click is working on first click now.

If you have better solution waiting for your response.