I have converted a web app I have from using normal javascript to using the AJAX Framework. I have a textbox inside an updatepanel, and the update pane is wired to watch for the click event from a button. I have been experiencing an issue where the click
event is fired twice, and it doesnt happen all the time either. I have noticed that most of the people it happens to are from places like Nigeria, India, etc, and only one from illinois. I am completely baffled. So I guess my question is: Could a slow
connection cause the double postback? What scenarios could cause such behavior given that you have 1 update panel, a button, and a textbox inside the updatepanel on the page?
I am shooting in the dark and any ideas you guys could throw out there would help. Thanks.
Are you absolutely sure they aren't double clicking? You'd be amazed how many people double click things like buttons and links, because they don't know better and it works from their perspective.
Also, if you think connection speed may be a factor, it would make sense that slower response times would increase impatient second clicks, since there's no visible indication that something's happening with a partial postback.
Thanks for the suggestion I will try those. The reason I dont think its a double click is because I have tried double clicking. I timestamp when the event is fired. I rigged it up in the buttons click event to return immediately if it has been less than
5 seconds and the contents of the textbox are the same as the contents I am currently processing. Sure enough I would get a double and sometimes a tripple post each 5 seconds apart.
Another question I have is that I have the text box setup with an onkeyup javascript event, within that javascript it calls the buttons click event if the Enter button is hit. If I disable the button, will it prevent the click event from being called at
all? (ps, i dont think its this onkeyup javascript that is doing it either because i completely removed it and got the same results).
This happens to me when I dynamically create a clickable control such as a button or linkbutton. The only thing I've found I can do about this is manually capture the click event by checking the Request["__EVENTNAME"] or Request["__EVENTARGUMENT"] . I usually
end up simulating the __doPostBack(name, argument) with my own values. Its unfortunate and alot of extra code, but it will work.
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Exiting news for all having double postback trouble!
Double postbacks are usually caused by one of two things:
1) bad markup in the page. run your rendered page through a validator.
along the same lines, since this is often experienced by custom control developers you should override the TagKey property and return a Div, as the default is Span and if your control renders divs, tables, etc... These are invalid inside of span tags.
2) if you are developing a custom control and have registered your postback using something like this:
because your control is hosted in a server side form you get a postback from your script calling __doPostback in the onclick and also a postback from the <form> tag's submit handler or whatever calling __doPostback. Returning false from your
onclick method will tell the form you don't want it to process the event so you get only the postback you really want.
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
I'm currently having a problem with control state, and I think this may have something to do with the
Double Postback I get.
I started a new thread to try to solve this, and one of my conclusions is that the double postback thing started to happen from the point I added an ImageButton to the page, without any event handlers, cliet scripts or anything. This is odd, but this is
not the first time I have problems with the ImageButton.
Here's another variation of this problem and a solution. I am using button controls as part of a WebControl with a postback handler. I forgot that button controls use submit as their default type attribute. So when I registered a postback script, I got
both the postback OnClick and the form submission. This is similar to the OnClientClick issue. To solve it, I change the type attribute to button, as follows:
In this particular case, the bad behavior was occurring in IE8 but not in Firefox. Once I changed the type attrbute the code worked fine in all browsers.
Member
3 Points
46 Posts
Double postback
Aug 17, 2007 02:35 PM|gdogg|LINK
I have converted a web app I have from using normal javascript to using the AJAX Framework. I have a textbox inside an updatepanel, and the update pane is wired to watch for the click event from a button. I have been experiencing an issue where the click event is fired twice, and it doesnt happen all the time either. I have noticed that most of the people it happens to are from places like Nigeria, India, etc, and only one from illinois. I am completely baffled. So I guess my question is: Could a slow connection cause the double postback? What scenarios could cause such behavior given that you have 1 update panel, a button, and a textbox inside the updatepanel on the page?
I am shooting in the dark and any ideas you guys could throw out there would help. Thanks.
Star
10226 Points
2494 Posts
ASPInsiders
MVP
Re: Double postback
Aug 17, 2007 03:11 PM|gt1329a|LINK
Are you absolutely sure they aren't double clicking? You'd be amazed how many people double click things like buttons and links, because they don't know better and it works from their perspective.
Also, if you think connection speed may be a factor, it would make sense that slower response times would increase impatient second clicks, since there's no visible indication that something's happening with a partial postback.
You could try disabling the button in a BeginRequest handler, similar to what I do here: http://encosia.com/index.php/2007/01/16/css-style-as-ajax-progress-indicator/
See if that stops the double submits.
A guide to combining jQuery and ASP.NET: jQuery for the ASP.NET developer
Member
3 Points
46 Posts
Re: Double postback
Aug 17, 2007 05:45 PM|gdogg|LINK
Thanks for the suggestion I will try those. The reason I dont think its a double click is because I have tried double clicking. I timestamp when the event is fired. I rigged it up in the buttons click event to return immediately if it has been less than 5 seconds and the contents of the textbox are the same as the contents I am currently processing. Sure enough I would get a double and sometimes a tripple post each 5 seconds apart.
Another question I have is that I have the text box setup with an onkeyup javascript event, within that javascript it calls the buttons click event if the Enter button is hit. If I disable the button, will it prevent the click event from being called at all? (ps, i dont think its this onkeyup javascript that is doing it either because i completely removed it and got the same results).
Star
10226 Points
2494 Posts
ASPInsiders
MVP
Re: Double postback
Aug 17, 2007 06:16 PM|gt1329a|LINK
A guide to combining jQuery and ASP.NET: jQuery for the ASP.NET developer
Member
195 Points
107 Posts
Re: Double postback
Aug 17, 2007 07:33 PM|rpack79|LINK
I had the same problem. I noticed that at the end of Protected Sub Page_Load.... Me.Load was listed twice. I dont know why it was there, but it was.
This can be beneficial to other community members reading the thread.
Thanks,
Ron
Member
505 Points
163 Posts
Re: Double postback
Aug 18, 2007 12:37 AM|Dested|LINK
This happens to me when I dynamically create a clickable control such as a button or linkbutton. The only thing I've found I can do about this is manually capture the click event by checking the Request["__EVENTNAME"] or Request["__EVENTARGUMENT"] . I usually end up simulating the __doPostBack(name, argument) with my own values. Its unfortunate and alot of extra code, but it will work.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Member
10 Points
4 Posts
Re: Double postback
Aug 31, 2007 09:17 AM|ScottLloyd|LINK
Exiting news for all having double postback trouble!
Double postbacks are usually caused by one of two things:
1) bad markup in the page. run your rendered page through a validator.
along the same lines, since this is often experienced by custom control developers you should override the TagKey property and return a Div, as the default is Span and if your control renders divs, tables, etc... These are invalid inside of span tags.
2) if you are developing a custom control and have registered your postback using something like this:
NewImageButton
.OnClientClick = Page.ClientScript.GetPostBackClientHyperlink(this, wcb.ControlType.ToString());You'll need to add this:
NewImageButton.OnClientClick += "; return false;";
because your control is hosted in a server side form you get a postback from your script calling __doPostback in the onclick and also a postback from the <form> tag's submit handler or whatever calling __doPostback. Returning false from your onclick method will tell the form you don't want it to process the event so you get only the postback you really want.
Scott Lloyd
Lloyd Software
double postback
Lloyd Software Development
Member
505 Points
163 Posts
Re: Double postback
Sep 01, 2007 09:15 AM|Dested|LINK
Thank you for this.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Member
25 Points
50 Posts
Re: Double postback
Jun 30, 2008 03:07 PM|levidad|LINK
Hi,
I'm currently having a problem with control state, and I think this may have something to do with the Double Postback I get.
I started a new thread to try to solve this, and one of my conclusions is that the double postback thing started to happen from the point I added an ImageButton to the page, without any event handlers, cliet scripts or anything. This is odd, but this is not the first time I have problems with the ImageButton.
You may wan't to track my thread: http://forums.asp.net/p/1283017/2457445.aspx#2457445
Thanks.
double postback ImageButton
None
0 Points
9 Posts
Re: Double postback
Apr 22, 2009 11:14 AM|pkpjpm|LINK
Here's another variation of this problem and a solution. I am using button controls as part of a WebControl with a postback handler. I forgot that button controls use submit as their default type attribute. So when I registered a postback script, I got both the postback OnClick and the form submission. This is similar to the OnClientClick issue. To solve it, I change the type attribute to button, as follows:
In this particular case, the bad behavior was occurring in IE8 but not in Firefox. Once I changed the type attrbute the code worked fine in all browsers.
Paul Keister
www.pjpm.biz
www.pjpm.biz