got this:
$('#myButton').click();
I click the Button from my Javascript(Jquery).. but it crea开发者_运维技巧tes 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 :(
$("#Button1").click(function(evt) {
// This stops the form submission.
evt.preventDefault();
});
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.
Is it a submit button or a simple button?
Normaly, you use the click like : $('#myButton').click(function(){ //your code javascript });
charles
精彩评论