2013-02-08 29 views
3

有很多代码,所以我想用短语来解释这个问题。我有一个母版页,其中包含对JavaScript文件的所有引用,并且具有使用母版页的页面。我在我的页面中使用更新面板,在更新面板中有一些表单,包括那个 - 具有回发功能(即dropdownlist)。问题是当状态发生变化并发生部分回发时,由于这些JavaScript而具有某些功能和效果的表单会失去所有功能。任何帮助,将不胜感激。如何在UpdatePanel部分回传后保留javascripts

+0

您可以查看以下链接http://jquerybyexample.blogspot.com/2010/09/use-jquery-and-ajax-with-aspnet-master.html – Sumant

回答

4

这是因为在使用更新面板进行部分回发后,您需要重新初始化JavaScript。这是一个普通的例子

<script type="text/javascript"> 
    // if you use jQuery, you can load them when dom is read. 
    $(document).ready(function() { 
     var prm = Sys.WebForms.PageRequestManager.getInstance();  
     prm.add_initializeRequest(InitializeRequest); 
     prm.add_endRequest(EndRequest); 

     // Place here the first init 
    });   

    function InitializeRequest(sender, args) { 
    } 

    function EndRequest(sender, args) { 
     // after update occur on UpdatePanel re-init what you need 

    } 
</script> 

相关问题:
Asp.Net UpdatePanel in Gridview Jquery DatePicker
How to get Id update panel that initial a request in javascript

网4后,您还可以使用简单的pageLoad功能,类似于在onload功能,而是由ASP处理.net并在首页加载时调用,但每次更新ajax后都会调用它。

function pageLoad() 
{ 
    // init here your javascript 
    // This is called when the page load first time 
    // and called again each time you have an Update inside an UpdatePanel 
} 

参考:http://msdn.microsoft.com/en-us/library/bb386417(v=vs.100).aspx