0

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 :(

2
  • Is #myButton a form element? Commented Aug 4, 2011 at 15:07
  • yes its a normal <asp:Button> on the page.. Commented Aug 4, 2011 at 15:15

3 Answers 3

2
$("#Button1").click(function(evt) {
// This stops the form submission.
evt.preventDefault();

});

Sign up to request clarification or add additional context in comments.

Comments

1

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.

3 Comments

With the click I want to go in a Method in my CodeBehind.. I don't want perform any Code in the click Event in Javascript..
@eMi, you have two possibilities: UpdatePanels or PageMethods
PageMethods look little bit complexing.. Will try an UpdatePanel.. thx 4 your help
0

Is it a submit button or a simple button?

Normaly, you use the click like : $('#myButton').click(function(){ //your code javascript });

charles

1 Comment

I use a hidden Button to be able opening a Method in Codebehind.. I don't want write JS Code...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.