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

六眼飞鱼酱① 提交于 2019-12-17 19:29:34

问题


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.


回答1:


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)




回答2:


Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(InitAccordion);
function InitAccordion(){       
   $('#accordion').accordion();}

This will work for postback and asyncpostback Raised after all content on the page is refreshed as a result of either a synchronous or an asynchronous postback. http://msdn.microsoft.com/en-us/library/bb397523(v=vs.100).aspx



来源:https://stackoverflow.com/questions/13856717/jquery-accordion-not-re-initiating-after-an-asp-net-postback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!