0

I have two buttons (ButtonA & ButtonB) and a textbox (TexboxA) on an aspx page.

On the TexboxA's blur, I call the Javascript event to click the ButtonA programmatically.

My question is:

  1. When I'm focussing on the TextBoxA, then I directly clicking the ButtonB, which onclick event fired first? ButtonA_Click - since I'm losing focus of TextBoxA and triggering ButtonA click programmatically, or ButtonB_Click - because I'm directly clicking it?

  2. How to prevent ButtonB_Click triggered before ButtonA_Click completely finished?

Aspx Code:

<asp:TextBox ID="TextBoxA" runat="server" onblur="ClickA();"/>

<asp:Button ID="ButtonA" runat="server" OnClick="ButtonA_Click();"/>

<asp:Button ID="ButtonB" runat="server" OnClick="ButtonB_Click();"/>

JS Code:

function ClickA(){
    document.getElementById('<%=ButtonA.ClientId%>').click();
}
Willy Lazuardi
  • 1,806
  • 4
  • 26
  • 41

1 Answers1

0

Maybe your whole logic isn't very good, but if you need to do something on client side before to call the server code, you can use the method OnClientClick of your Button.

This allows also to abort the server side method click.

See here for example :

Asp .NET Button - OnClientClick="return function()" vs OnClientClick="function()" And https://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.button.onclientclick(v=vs.110).aspx

If the execution order of server side code matters, maybe you should ensure it on server side instead of trying to constrain it on client side.

Community
  • 1
  • 1
AFract
  • 8,868
  • 6
  • 48
  • 70