Razor
Razor

Reputation: 17498

asp.net generating onclick event automatically for button

ASP.NET seems to be generating its own onclick event for any buttons that are generated.

Looks like this

javascript:__doPostBack(

This is preventing jQuery from working correctly.

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

Many thanks

Upvotes: 0

Views: 406

Answers (2)

user434917
user434917

Reputation:

<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();
});

Upvotes: 0

jeroen.verhoest
jeroen.verhoest

Reputation: 5183

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

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

   //your code

   return false;****
});

Upvotes: 2

Related Questions