Run javascript function before executing a server function

0

I have a web page in C # ASP that when I press a button, it passes me to another page by calling a server method with onServerClick. I need to run a javascript on the page before executing the server method or that the screen does not refresh when I run the onServerClick server method (ajax style)

    
asked by Popularfan 04.10.2018 в 09:55
source

1 answer

1

If the button is an asp: button, you have to use the OnClientClick events for the Javascript code, and the OnClick for the server code.

<asp:Button ID="btnButton" runat="server" Text="Botón Button" OnClick="boton_Click" OnClientClick="javascript:BotonPulsado();" />

If the button is an input type="button", the events are OnClick for Javascript, and OnServerClick for server code.

<input type="button" id="btnInput" value="Botón Input" runat="server" onserverclick="boton_Click" onclick="javascript:BotonPulsado();" />

    
answered by 04.10.2018 в 17:06