Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
617 views
in Technique[技术] by (71.8m points)

jquery accordion not re-initiating after an asp.Net postback

I'm firing up a jquery accordion with:

$(document).ready(function(){
   $('#accordion').accordion();
});

Problem is this is an .asp.NET application and if the page fires a postback is destroys the accordion. How do I re-initiate the accordion upon postback?

Sorry I'm not an expert on asp.NET, and also sorry I can't give you a link to the example, this is because it's a password protected application.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to re-initlaize the accordion after the post back with the UpdatePanel functions as:

<script type="text/javascript"> 
$(document).ready(function(){
    var prm = Sys.WebForms.PageRequestManager.getInstance();    
        prm.add_initializeRequest(InitializeRequest);
        prm.add_endRequest(EndRequest);
   // on page ready first init of your accordion
   $('#accordion').accordion();
});


function InitializeRequest(sender, args) {      
}

function EndRequest(sender, args) {
     // after the UpdatePanel finish the render from ajax call
     //  and the DOM is ready, re-initilize the accordion
     $('#accordion').accordion();
}
</script>

Relative:
Asp.Net UpdatePanel in Gridview Jquery DatePicker
ASP.Net : Need to run javascript on update panel load completed
How do you get client-side script to execute on an ASP.NET postback? (from an UpdatePanel)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...