Spot the place that submits the form in ASP .NET?

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.

Up vote 0 down vote favorite share g+ share fb share tw.

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? Asp.net postback dopostback link|improve this question edited Jul 27 '10 at 14:02David11.7k1021 asked Jul 27 '10 at 13:54dragonfly659715 76% accept rate.

– dragonfly Jul 27 '10 at 14:18 either have autowireup=true or remove manual wiring. – TheGeekYouNeed Jul 27 '10 at 14:53 With AutoEventWireup="True", ASP. NET will automatically wire up common event handlers such as Page_Load, so you don't need to do it by hand (it exists to help you avoid such uninteresting boilerplate code).

But if you're doing it in the code, you must set AutoEventWireup="false", or else you end up with the event handlers registered twice and thus called twice as well. I'd recommend removing the manual wiring, because less boilerplate code equals better readability, which is important. – cjberg Jul 27 '10 at 15:11 Here's a question about AutoEventWireup, with answers that explains how it work: stackoverflow.com/questions/680878/… – cjberg Jul 27 '10 at 15:19 The reason why I asked about it, is that it won't solve my issue, which is: TWO REQUESTS ARE SENT FROM THE BROWSER :) and calling Page_Load twice is just a implication.

Thanks – dragonfly Jul 27 '107 at 7:33.

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?

I'm glad you found it. The same thing has happened to me as well. Today I always avoid using the onclick attribute directly, favoring jquery's bind/click instead.

That way you get a consistent programming model that doesn't vary between browsers, and a better separation of markup and JavaScript code. – cjberg Jul 30 '10 at 15:50.

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?

Those requests contain the same form data etc... It's input, type="image" with onclick="__doPostBack...". – dragonfly Jul 27 '10 at 14:15.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions