找出 ASP .NET 中提交表单的位置
我在 ASP .NET 页面上有一个表单,其中按钮 onclick 事件附加到 doPostBack 函数。 但是,当我单击该按钮时,表单会提交两次。服务器端调试器输入 Page_Load 两次,Fiddler 记录两个 aspx 请求等,没有 302 重定向等,这是非常简单的页面。
当我在 __doPostBack 函数中设置断点时,它也会被调用一次(也许这只是一种幻觉)。
是否有机会更深入地调试客户端以发现问题?
谢谢,帕韦乌
I have a form on ASP .NET page, with button onclick event attached to doPostBack function.
However when I click that button form gets submitted twice. Server side debugger enters Page_Load twice, Fiddler records two aspx requests etc, there are no 302 redirects etc, it's pretty straightforward page.
When I set breakpoint in __doPostBack function it's also called once (perhaps it's just an illusion).
Is there a chance to debug client side even more deeper to find the issue?
Thanks, Paweł
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否手动连接事件处理程序?如果是这样,您应该检查 ASPX 的 Page 指令中是否 AutoEventWireup="true"。如果是,请将其更改为 false 或删除手动接线。当您使用设计器文件将旧页面升级到较新的 Web 应用程序格式时,可能会发生这种情况。
Do you wire up the event handlers manually? If so, you should check if AutoEventWireup="true" in the ASPX's Page directive. If so, change it to false or remove the manual wiring. It can happen when you upgrade an old page to the newer web application format with a designer file.
好的。明白了:输入类型=“图像”
当我将其修改为:
并且两个请求问题消失了。 Fiddler 仅记录了一个请求,Page_Load 被调用一次,一切都很整洁。
因此,在使用会导致点击时自动提交表单的 HTML 元素时要小心;)
谢谢,Paweł
Ok. got it: input type="image" had
When I modified it to:
and two requests issue went away. Only one request was recorded by Fiddler, Page_Load is called once and everything is neat.
So be careful when using HTML elements that cause automatic form submission on click ;)
Thanks, Paweł
听起来有两件事导致了回发。该按钮是提交按钮并且还有 onclick 处理程序吗?这会导致这种行为。
您在 Fiddler 中看到的 2 个 ASPX 请求是否相同,或者只是略有不同?
It sounds like there are two things causing a postback. Is the button a submit button and also has an onclick handler? That would cause this behavior.
Are the 2 ASPX requests you see in Fiddler the same, or just slightly different?