Mozilla 在 WebForm_DoPostBackWithOptions JavaScript 函数中获得奇怪的值

发布于 2024-11-24 05:13:14 字数 3337 浏览 2 评论 0原文

  1. 变量 options.eventTarget 从哪里来?
  2. 如果这个函数是由 ASP.NET 代码生成的,我该如何修复 Mozilla 的这个函数?
  3. 这个 JavaScript 函数有什么用?

当调用锚标记时,Mozilla Firefox 会在此函数末尾获取 options.eventTarget 的值。保存(锚标记)按钮在 Mozilla 中不起作用,所以我试图找出原因。

ExplorerPageHtmlLeft$ct...aveCancelDelete$LBuSave <===== problem

当调用锚标记时,Internet Explorer 会在此函数末尾获取 options.eventTarget 的值。 “保存”(锚标记)按钮在 Internet Explorer 中工作正常。

ExplorerPageHtmlLeft$ctl02$ctl00$SaveCancelDelete$LBuSave

下面是展开的代码,以便于阅读


Mozilla Firefox 保存按钮(已损坏):

<a
id="ExplorerPageHtmlLeft_ctl02_ctl00_SaveCancelDelete_LBuSave"
href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ExplorerPageHtmlLeft$ctl02$ctl00$SaveCancelDelete$LBuSave", "", true, "", "", false, true))"
onclick="javascript:encryptField(document.getElementById('ExplorerPageHtmlLeft_ctl02_ctl00_SaveCancelDelete_TxtPassword'),document.getElementById('IHHidden'));"
>
<img border="0" alt="Save" src="/images/save.gif">
</a>

Internet Explorer 保存按钮(工作正常):

<a
onclick="javascript:encryptField(document.getElementById('ExplorerPageHtmlLeft_ctl02_ctl00_SaveCancelDelete_TxtPassword'),document.getElementById('IHHidden'));"
id="ExplorerPageHtmlLeft_ctl02_ctl00_SaveCancelDelete_LBuSave"
href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ExplorerPageHtmlLeft$ctl02$ctl00$SaveCancelDelete$LBuSave&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))"
>
<img src="/images/save.gif" border="0" alt="Save">
</a>

这是 JavaScript 函数:

function WebForm_DoPostBackWithOptions(options) {
    var validationResult = true;
    if (options.validation) {
        if (typeof(Page_ClientValidate) == 'function') {
            validationResult = Page_ClientValidate(options.validationGroup);
        }
    }
    if (validationResult) {
        if ((typeof(options.actionUrl) != "undefined") && (options.actionUrl != null) && (options.actionUrl.length > 0)) {
            theForm.action = options.actionUrl;
        }
        if (options.trackFocus) {
            var lastFocus = theForm.elements["__LASTFOCUS"];
            if ((typeof(lastFocus) != "undefined") && (lastFocus != null)) {
                if (typeof(document.activeElement) == "undefined") {
                    lastFocus.value = options.eventTarget;
                }
                else {
                    var active = document.activeElement;
                    if ((typeof(active) != "undefined") && (active != null)) {
                        if ((typeof(active.id) != "undefined") && (active.id != null) && (active.id.length > 0)) {
                            lastFocus.value = active.id;
                        }
                        else if (typeof(active.name) != "undefined") {
                            lastFocus.value = active.name;
                        }
                    }
                }
            }
        }
    }
    if (options.clientSubmit) {
        __doPostBack(**options.eventTarget**, options.eventArgument);
    }
}
  1. Where does the variable options.eventTarget come from?
  2. How can I fix this function for Mozilla if it's generated by ASP.NET code?
  3. What is this JavaScript function used for?

Mozilla Firefox gets this value for options.eventTarget at the end of this function when the anchor tag is called. The Save (anchor tag) button doesn't work in Mozilla, so I'm trying to figure out why.

ExplorerPageHtmlLeft$ct...aveCancelDelete$LBuSave <===== problem

Internet Explorer gets this value for options.eventTarget at the end of this function when the anchor tag is called. The Save (anchor tag) button works fine in Internet Explorer.

ExplorerPageHtmlLeft$ctl02$ctl00$SaveCancelDelete$LBuSave

Here is the code spread out so it's easy to read


Mozilla Firefox Save button (broken):

<a
id="ExplorerPageHtmlLeft_ctl02_ctl00_SaveCancelDelete_LBuSave"
href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ExplorerPageHtmlLeft$ctl02$ctl00$SaveCancelDelete$LBuSave", "", true, "", "", false, true))"
onclick="javascript:encryptField(document.getElementById('ExplorerPageHtmlLeft_ctl02_ctl00_SaveCancelDelete_TxtPassword'),document.getElementById('IHHidden'));"
>
<img border="0" alt="Save" src="/images/save.gif">
</a>

Internet Explorer Save button (works fine):

<a
onclick="javascript:encryptField(document.getElementById('ExplorerPageHtmlLeft_ctl02_ctl00_SaveCancelDelete_TxtPassword'),document.getElementById('IHHidden'));"
id="ExplorerPageHtmlLeft_ctl02_ctl00_SaveCancelDelete_LBuSave"
href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ExplorerPageHtmlLeft$ctl02$ctl00$SaveCancelDelete$LBuSave", "", true, "", "", false, true))"
>
<img src="/images/save.gif" border="0" alt="Save">
</a>

Here is the JavaScript function:

function WebForm_DoPostBackWithOptions(options) {
    var validationResult = true;
    if (options.validation) {
        if (typeof(Page_ClientValidate) == 'function') {
            validationResult = Page_ClientValidate(options.validationGroup);
        }
    }
    if (validationResult) {
        if ((typeof(options.actionUrl) != "undefined") && (options.actionUrl != null) && (options.actionUrl.length > 0)) {
            theForm.action = options.actionUrl;
        }
        if (options.trackFocus) {
            var lastFocus = theForm.elements["__LASTFOCUS"];
            if ((typeof(lastFocus) != "undefined") && (lastFocus != null)) {
                if (typeof(document.activeElement) == "undefined") {
                    lastFocus.value = options.eventTarget;
                }
                else {
                    var active = document.activeElement;
                    if ((typeof(active) != "undefined") && (active != null)) {
                        if ((typeof(active.id) != "undefined") && (active.id != null) && (active.id.length > 0)) {
                            lastFocus.value = active.id;
                        }
                        else if (typeof(active.name) != "undefined") {
                            lastFocus.value = active.name;
                        }
                    }
                }
            }
        }
    }
    if (options.clientSubmit) {
        __doPostBack(**options.eventTarget**, options.eventArgument);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我早已燃尽 2024-12-01 05:13:14

好吧,看来 options.eventTarget 的值根本不是问题。奇怪的是,正好是50个字符。

Firebug 中的 options.eventTarget:
“ExplorerPageHtmlLeft$ct...aveCancelDelete$LBuSave”

事实证明,Mozilla Firefox Firebug 仅显示 50 个字符。它采用控件客户端 ID 的第一部分和最后一部分(以及中间的 3 个点)并将其粘贴到Firebug 监视变量中的 value 字段。为了确认,我只是将“alert(options.eventTarget)”放入监视变量中,它显示了整个值。所以绝对不是这样的!

我仍然不知道为什么我的 LinkBut​​ton 不在 Mozilla 的后台代码中调用事件处理程序,但在 Internet Explorer 中却可以。我想一旦我有了更多信息,我就会发布它(可能是在不同的问题上)。这可能与单击我的链接按钮时打开验证有关。我猜这就是 ASP.NET 自动将此函数放入客户端代码的原因。

Well, it appears that the value of the options.eventTarget is not the issue at all. It was strange that it was exactly exactly 50 characters.

options.eventTarget in Firebug:
"ExplorerPageHtmlLeft$ct...aveCancelDelete$LBuSave"

It turns out that Mozilla Firefox Firebug only shows 50 characters.. it takes the first and last part of the control client ID (and the 3 dots in the middle) and sticks that into the value field within the Firebug watch variable. To confirm, I just put "alert(options.eventTarget)" into the watch variable, and it showed the entire value. So that definitely isn't it!

I still have no idea why my LinkButton doesn't call my event handler in my code behind in Mozilla, but it does in Internet Explorer. I guess once I have more information, I will post it (probably on a different question). It might have something to do with having validation turned on when my link button is clicked. That's what causes ASP.NET to put this function into the client code automatically I guess.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文