UpdatePanel 部分回发后如何保留 javascripts [英] how to keep javascripts after UpdatePanel partial postback

查看:35
本文介绍了UpdatePanel 部分回发后如何保留 javascripts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多代码,所以我想用文字简短地解释这个问题.我有一个母版页,其中包含对 javascript 文件的所有引用,并且有使用母版页的页面.我在我的页面中使用更新面板,在更新面板内有一些表单,包括具有回发功能的表单(即下拉列表).问题是当状态发生变化并发生部分回发时,由于这些 javascripts 具有一些功能和效果的表单,然后失去所有功能.任何帮助将不胜感激.

There is a lot of code so I want to explain the issue shortly in words. I have a Master page, that includes all references to javascript files and have the pages that use the master page. I use update panel in my pages and inside the update panel there are some forms including that one-has postback capability(ie dropdownlist). The problem is when the state changes and a partial postback occurs, the forms which has some capabilities and effects because of those javascripts, then lose all the functionality. Any help would be appreciated.

推荐答案

这是因为在使用更新面板部分回发后,您需要重新初始化 javascript.这是一个通用示例

This is because after the partial post back with the Update panel you need to re-initialize the javascript. Here is a general example

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

相关问题:
Gridview Jquery DatePicker 中的 Asp.Net UpdatePanel
如何获取 ID在 javascript 中初始化请求的更新面板

net 4 之后你也可以简单的使用pageLoad 函数,类似于OnLoad 函数,不过是由asp.net 处理,在第一次页面加载时调用,但也调用之后每次ajax更新.

After the net 4 you can also simple use the pageLoad function, is similar to the OnLoad function, but is handled by asp.net and is called on the first page load, but also called after each ajax update.

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

这篇关于UpdatePanel 部分回发后如何保留 javascripts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆