对于UpdatePanel和ClientIDMode ="Static"的可能解决方案. [英] Possible solution to UpdatePanel and ClientIDMode="Static"

查看:34
本文介绍了对于UpdatePanel和ClientIDMode ="Static"的可能解决方案.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直到处寻找Asp.NET中静态ClientIDMode + UpdatePanel的解决方案,如

I've been looking everywhere for a solution to the static ClientIDMode + UpdatePanel in Asp.NET, as seen in http://connect.microsoft.com/VisualStudio/feedback/details/584991/clientidmode-static-in-updatepanel-fails-to-do-async-postback

问题出在Sys.WebForms.PageRequestManager. uniqueIDToClientID函数中,该函数通过将"$"字符替换为""来将名称转换为id.我做了一个似乎可行的修复程序,但是我希望你们告诉我您的想法以及我是否缺少某些东西.非常感谢!

The problem is in the Sys.WebForms.PageRequestManager.uniqueIDToClientID function, that converts names to id by replacing "$" characters to "". I made a fix that seems to work but I want you guys to tell me what you think and if I'm missing something. Thanks a lot!

var old_uniqueIDToClientID = Sys.WebForms.PageRequestManager.prototype._uniqueIDToClientID;
Sys.WebForms.PageRequestManager.prototype._uniqueIDToClientID = function (arg) {
    var element = this._form.elements[arg];
    return (element) ? element.id : old_uniqueIDToClientID(arg)
}

推荐答案

我们进行了类似的修复,但是我们更改了搜索导致回发的元素所涉及的另一个函数.

We made a similar fix, but we changed another function that was involved in the search for the element that caused the postback.

我们已将以下代码放置在母版页的底部,以确保在scriptmanager加载其脚本之后将其包括在内.从本质上讲,它一直在修改ID,直到找到导致回发的元素为止.原始代码通过从名称的右侧删除由美元符号分隔的标记来搜索该元素.因此,"$ ctl00 $ ddl001"将变为"$ ctl00".如果您使用的是静态ID,则该后缀可能永远不会存在.我们修改了从左开始的功能,并删除了容器名称,直到找到一个元素.

We have placed the following code at the bottom of our master page to make sure that it is included after the scriptmanager has loaded its scripts. Essentially it keeps modifying the id until it finds the element that caused the postback. The original code searched for the element by removing tokens from the right hand side of the name delimited by the dollar sign. So "$ctl00$ddl001" would become "$ctl00". If you are using static ids then that suffix might never exist. We modified the function to start from the left and remove the container names until an element is found.

现在看来,它对我们有用.:)

It seems to work for us for now. :)

   if (Sys.WebForms.PageRequestManager) {
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm._findNearestElement = function (uniqueID) {
        while (uniqueID.length > 0) {
            var clientID = this._uniqueIDToClientID(uniqueID);
            var element = document.getElementById(clientID);
            if (element) {
                return element;
            }
            var indexOfFirstDollar = uniqueID.indexOf('$', 1);
            if (indexOfFirstDollar === -1) {
                return null;
            }
            uniqueID = uniqueID.substring(indexOfFirstDollar + 1, uniqueID.length);
        }
        return null;
    };
}

这篇关于对于UpdatePanel和ClientIDMode ="Static"的可能解决方案.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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