Which event executes first, javascript or asp.net?

1

I have a method in javascript on a button, which is triggered with the click of the button, but this same button triggers an ASP.NET event. The js event performs a method that processes a value and this value I play inside an asp (). The asp event, uses this value (from hidden) for another process. My problem is that it seems that the asp event is processing before JS so when asp tries to get the value generated by JS (which should be hidden), the value is empty.

Any idea how to run js first in this case? or any other ideas?

document
      .getElementById("ContentPlaceHolder1_cmdAvancarEnder‌​eco")
      .addEventListen‌​er("click", getHashSender); 
Private Sub cmdAvancarEndereco_Click(sender As Object, e As EventArgs)
                                      Handles cmdAvancarEndereco.Click
<asp:button ID="cmdAvancarEndereco" runat="server" 
                  cssclass="btn btn-success btn-lg" text="Avançar >">
</asp:button>
    
asked by anonymous 01.02.2017 / 20:25

2 answers

1

The solution found was in the onClick event of the inform a return false; button, thus barring the codebehind event, and only when my hidden is filled, is the submit event of the form to process the data ( in case I could force the event click , but the solution changed).

    
06.03.2017 / 19:38
1

You can take control of .cs and do it only by .js .

Transforms the Private Sub cmdAvancarEndereco_Click(sender As Object, e As EventArgs) method into a normal Public Sub cmdAvancarEndereco_Click({ parametros_necessarios }) method. Hence the code asp will be called by your javascript after being processed by it.

document.getElementById("ContentPlaceHolder1_cmdAvancarEnder‌​eco").addEventListen‌​er("click", function(evt) {
   callPostBack(null, this, [urlcmdAvancarEndereco_Click], [parametros]);
}); 

This guarantees that before arriving at the code backend will go through the .js .

    
02.02.2017 / 17:52