开发者

Spot the place that submits the form in ASP .NET

开发者 https://www.devze.com 2023-01-09 05:59 出处:网络
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, Fidd

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 deb开发者_如何学JAVAug client side even more deeper to find the issue?

Thanks, Paweł


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.


Ok. got it: input type="image" had

onclick="__doPostBack(.....)" 

When I modified it to:

onclick="_doPostBack(...); return false;"

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ł


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消