Mozilla 在 WebForm_DoPostBackWithOptions JavaScript 函数中获得奇怪的值
- 变量
options.eventTarget
从哪里来? - 如果这个函数是由 ASP.NET 代码生成的,我该如何修复 Mozilla 的这个函数?
- 这个 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("ExplorerPageHtmlLeft$ctl02$ctl00$SaveCancelDelete$LBuSave", "", true, "", "", 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);
}
}
- Where does the variable
options.eventTarget
come from? - How can I fix this function for Mozilla if it's generated by ASP.NET code?
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,看来 options.eventTarget 的值根本不是问题。奇怪的是,正好是50个字符。
Firebug 中的 options.eventTarget:
“ExplorerPageHtmlLeft$ct...aveCancelDelete$LBuSave”
事实证明,Mozilla Firefox Firebug 仅显示 50 个字符。它采用控件客户端 ID 的第一部分和最后一部分(以及中间的 3 个点)并将其粘贴到Firebug 监视变量中的 value 字段。为了确认,我只是将“alert(options.eventTarget)”放入监视变量中,它显示了整个值。所以绝对不是这样的!
我仍然不知道为什么我的 LinkButton 不在 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.