user647078
user647078

Reputation: 11

JQuery causing postback in .NET

I created an adrotator in jquery for the first time and when I use it on a page that uses pagemethods to do ajax calls to the server and show a modal. The page posts back. When I remove the rotator the page works as it should. In the rotator I have the following code in the document ready function.

    $(".animation_control a.play").live('click', function () {        
        $(this).removeClass('play');
        $(this).addClass('pause');
        Play();
    });

    $(".animation_control a.pause").live('click', function () {
        $(this).removeClass('pause');
        $(this).addClass('play');
        clearInterval(timer);
    });

    $(".animation_control a.pause").click(function () {

    });

    //Toggle Teaser
    $("a.collapse").click(function () {
        $(".main_image .block").slideToggle();
        $("a.collapse").toggleClass("show");
    });

If I comment out this code the page stops the complete page refresh and and posts back async like it should. Any ideas on why this would cause the page to do a complete postback instead of a partial one?

Upvotes: 0

Views: 1322

Answers (3)

Mohammed Swillam
Mohammed Swillam

Reputation: 9242

Anchors are used to navigate to a page/region in the same page, and according to this part, clicking an anchor MUST move us to the HREF that the anchor is pointing to.

in order to cancle this default behavior, we will need to do either return false or to prevent the default action using jQuery.

This is an example of what i mean.

Upvotes: 0

Praveen Prasad
Praveen Prasad

Reputation: 32107

.live('click', function (e) {       
e.preventDefault();

//your code

Upvotes: 2

Paul Creasey
Paul Creasey

Reputation: 28824

As a guess, since the code is incomplete, you should add return false to your event handlers to prevent the links from actually firing.

Upvotes: 3

Related Questions