Asp.net automatically generates onclick event for button

ASP.NET seems to emit its own onclick event for any generated buttons.

Looks like this

JavaScript: __ doPostBack (

This prevents jQuery from working properly.

Does anyone know how to stop the asp.net engine from doing this?

Many thanks

0


a source to share


2 answers


You just need to add return false to the jquery code that handles the button.



$("myaspbutton").click(function(e){

   //your code

   return false;****
});

      

+2


a source


<asp:Buttton runat="server" ID="myButton" Text="MyButton" OnClientClick="alert('hi');" />

      

Update:
you can bind the click event dynamically:



$('#<%=myButton.ClientID%>').click(function(e) {
//your code here
e.preventDefault();
});

      

0


a source







All Articles