Reputation: 97
got this:
$('#myButton').click();
I click the Button from my Javascript(Jquery).. but it creates a Postback, what I don't want.. How can I "disable" this?
And if no one knows how.. should I try it with updatePanels? How would it work?
Hope u guys can help me :(
Upvotes: 0
Views: 1834
Reputation: 1039508
You could subscribe for the .click event handler of the button and then perform the necessary actions and return false in order to cancel the default postback. If you want to invoke a controller action on the codebehind with jQuery you could use Page Methods
$('#myButton').click(function() {
// See here http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
// cancel the default action of the button which is a postback
return false;
});
Obviously depending on what you are trying to achieve there might be different techniques. If you want to send an AJAX request you could use the $.ajax()
function.
If you decide to use UpdatePanels, you no longer need jQuery. They use Microsoft Ajax library and handle asynchronous AJAX requests automatically. Here's an article on MSDN which provides a nice overview of UpdatePanels.
Upvotes: 1
Reputation: 1968
$("#Button1").click(function(evt) {
// This stops the form submission.
evt.preventDefault();
});
Upvotes: 2
Reputation: 5312
Is it a submit button or a simple button?
Normaly, you use the click like : $('#myButton').click(function(){ //your code javascript });
charles
Upvotes: 0