Question

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ł

Was it helpful?

Solution 2

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ł

OTHER TIPS

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.

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top