C# __doPostBack 在 Firefox 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/55360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 10:08:49  来源:igfitidea点击:

__doPostBack is not working in firefox

提问by Dan Williams

The __doPostBack is not working in firefox 3 (have not checked 2). Everything is working great in IE 6&7 and it even works in Chrome??

__doPostBack 在 Firefox 3 中不起作用(尚未检查 2)。在 IE 6&7 中一切正常,甚至在 Chrome 中也能正常工作??

It's a simple asp:LinkButton with an OnClick event

这是一个带有 OnClick 事件的简单 asp:LinkBut​​ton

<asp:LinkButton ID="DeleteAllPicturesLinkButton" Enabled="False" OnClientClick="javascript:return confirm('Are you sure you want to delete all pictures? \n This action cannot be undone.');" OnClick="DeletePictureLinkButton_Click" CommandName="DeleteAll" CssClass="button" runat="server">

The javascript confirm is firing so I know the javascript is working, it's specirically the __doPostBack event. There is a lot more going on on the page, just didn't know if it's work it to post the entire page.

javascript 确认正在触发,所以我知道 javascript 正在工作,特别是 __doPostBack 事件。页面上还有很多事情要做,只是不知道发布整个页面是否可行。

I enable the control on the page load event.

我在页面加载事件上启用控件。

Any ideas?

有任何想法吗?



I hope this is the correct way to do this, but I found the answer. I figured I'd put it up here rather then in a stackoverflow "answer"

我希望这是正确的方法,但我找到了答案。我想我会把它放在这里而不是放在一个stackoverflow“答案”中

Seems it had something to do with nesting ajax toolkit UpdatePanel. When I removed the top level panel it was fixed.

似乎它与嵌套 ajax 工具包 UpdatePanel 有关。当我卸下顶层面板时,它已修复。

Hope this helps if anyone else has the same problem. I still don't know what specifically was causing the problem, but that was the solution for me.

如果其他人有同样的问题,希望这会有所帮助。我仍然不知道是什么导致了这个问题,但这就是我的解决方案。

采纳答案by Seibar

Check your User Agent string. This same thing happened to me one time and I realized it was because I was testing out some pages as "googlebot". The JavaScript that is generated depends on knowing what the user agent is.

检查您的用户代理字符串。有一次我也发生了同样的事情,我意识到这是因为我正在测试一些页面为“googlebot”。生成的 JavaScript 取决于了解用户代理是什么。

From http://support.mozilla.com/tiki-view_forum_thread.php?locale=tr&comments_parentId=160492&forumId=1:

来自http://support.mozilla.com/tiki-view_forum_thread.php?locale=tr&comments_parentId=160492&forumId=1

To reset your user agent string type about:config into the location bar and press enter. This brings up a list of preferences. Enter general.useragent into the filter box, this should show a few preferences (probably 4 of them). If any have the status user set, right-click on the preference and choose Reset

要将您的用户代理字符串类型 about:config 重置到位置栏中,然后按 Enter。这会显示一个首选项列表。在过滤器框中输入 general.useragent ,这应该显示一些首选项(可能是其中的 4 个)。如果有状态用户设置,请右键单击首选项并选择重置

回答by Darren Kopp

Is it because you are doing returnconfirm? seems like the return statement should prevent the rest of the code from firing. i would think an if statement would work

是因为你在做退货确认吗?似乎 return 语句应该防止其余代码被触发。我认为 if 语句会起作用

if (!confirm(...)) { return false; } _doPostBack(...);

Can you post all the js code in the OnClick of the link?

你能在链接的OnClick中发布所有的js代码吗?

EDIT: aha, forgot that link button emits code like this

编辑:啊哈,忘了链接按钮会发出这样的代码

<a href="javascript:__doPostBack()" onclick="return confirm()" />

回答by Dan Williams

With or without the OnClientClick event it still doesn't work.

不管有没有 OnClientClick 事件,它仍然不起作用。

The _doPostBack event is the auto generated javascript that .NET produces.

_doPostBack 事件是 .NET 生成的自动生成的 javascript。

function __doPostBack(eventTarget, eventArgument) {

    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {

        theForm.__EVENTTARGET.value = eventTarget;

        theForm.__EVENTARGUMENT.value = eventArgument;

        theForm.submit();

    }

}

*The &95; are underscores, seems to be a problem with the stackoverflow code block format.

*&95; 是下划线,似乎是stackoverflow代码块格式的问题。

回答by Paulj

this might seem elemental, but did you verify that your firefox settings aren't set to interfere with the postback? Sometimes I encounter similar problems due to a odd browser configuration I had from a debugging session.

这可能看起来很基本,但是您是否确认您的 Firefox 设置未设置为干扰回发?有时我会遇到类似的问题,因为我在调试会话中遇到了奇怪的浏览器配置。

回答by Darren Kopp

Now that i think about it, as noted in my last edit, you want to drop the javascript: in the on client click property. It's not needed, because the onclick event is javascript as it is. try that, see if that works.

现在我考虑了一下,正如我在上次编辑中所指出的,您想删除 javascript: 在客户端单击属性中。它不是必需的,因为 onclick 事件是 javascript。试试看,看看是否有效。

回答by moza

Are you handling the PageLoad event? If so, try the following

你在处理 PageLoad 事件吗?如果是这样,请尝试以下操作

if (!isPostBack)
{
    //do something
}
else if (Request.Form["__EVENTTARGET"].ToLower().IndexOf("myevent") >= 0)
{
    //call appropriate function.
}

Check if you are getting a call this way, if so then maybe the event is not wired and nedes to be explicitly called.

检查您是否以这种方式接听电话,如果是这样,则事件可能未连接并且需要显式调用。

回答by Jimmy

what do you expect from "Enabled = 'false'" ?

你对“Enabled = 'false'”有什么期望?

回答by seanb

I have had problems with firebug on some web forms, something to do with the network analyser can screw with postbacks.

我在某些 Web 表单上遇到了 firebug 问题,与网络分析器有关的事情可能会导致回发。

回答by Dan Williams

Seems it had something to do with nesting ajax toolkit UpdatePanel. When I removed the top level panel it was fixed.

似乎它与嵌套 ajax 工具包 UpdatePanel 有关。当我卸下顶层面板时,它已修复。

Hope this helps if anyone else has the same problem.

如果其他人有同样的问题,希望这会有所帮助。

回答by pearcewg

I had this exact same issue in a web app I was working on, and I tried solving it for hours.

我在我正在开发的一个网络应用程序中遇到了这个完全相同的问题,我尝试解决它几个小时。

Eventually, I did a NEW webform, dropped a linkbutton in it, and it worked perfectly!

最终,我做了一个新的网络表单,在里面放了一个链接按钮,它工作得很好!

I then noticed the following issue:

然后我注意到以下问题:

...

I switch the order to the following, and it immediately was fixed: ...

我将顺序切换为以下,并立即修复:...

IE had no issue either way (that I noticed anyway).

IE 没有任何问题(无论如何我都注意到了)。