I recently wrote a pretty high-intensity(about 200K pageviews/day) site. It worked perfectly in testing, and in the beginning everything was fine. Yesterday though, the ad network that the site is on experienced some problems, resulting in some IE clients(problem
did not show up in firefox) getting very, very long load times(my best guess is it's because firefox uses multiple pipes to download content, while many ie clients only use one, so they stalled on the ad content, but I'm merely guessing. This is not the point).
I noticed that I started getting alot of ArgumentExceptions in my log, more specifically, this:
System.ArgumentException: Invalid postback or callback argument. Event validation is enabled using in configuration or in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
at System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument)
at System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument)
at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Normally, this would be fine - it's an exception thrown when people try to post harmful code in a postback(from what I understand), but in this case, it was being thrown all over the place. From what I've managed to test, the exception also gets thrown
if someone tries to use a server control that raises a postback before the page is fully loaded(Finally, I got to the point!).
My question: Why does it do this, and how can I change this behaviour? I'd rather keep enableEventValidation on, since I don't trust the people out there overly much. I can of course catch the exception and ignore it, but this would still mean it's broken,
only I won't see it, which I don't want either. Hoping for some help from you folks. :)
Best regards,
Eric Johansson
SYSteam Evolution
www.systeam.se
I also had this error once ... is it only happening in IE6?
Well, I'm not sure what the exact cause is but you should google for "Invalid postback or callback argument" .... lots of links will show up.
Don't look at the ones saying you should disable the event validation ... that's just ignoring the real cause of the problem.
But I found some more useful links ...
http://communityserver.org/forums/t/466293.aspx : here they talk about that maybe the binding in the load event is the problem, and not putting it in the NOT ISPOSTBACK, they also provide a possible
fix
and so on .....
I also think the cause is the databinding in the wrong place .... not specifically double databinding ...
Not much of a solution but I hope it helps ...
Wim
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Marked as answer by EricJohansson on Aug 12, 2007 07:39 PM
The error occured in IE7, but it was because it halted halfway through loading a page on the ads during the ad networks trouble. My guess is that the bug will occur similarily in FF or IE6 on a sufficiently large webpage.
If I'd been doing databinding on all the pages that displayed the error, then sure, I'd guess is was connected; but I'm not. Most of the pages that displayed the error contains no databinding at all. They do however have some action(button_click, textbox_changed)
associated with a server control. If the event triggered before the page had loaded completely, the exception was thrown.
Best regards,
Eric Johansson
SYSteam Evolution
www.systeam.se
Also, is it possible to replicate the problem in a small working code example, that would be great to test/debug on.
Kind regards,
Wim
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
I'd like to thank you for sticking in there even when I was to tired to properly read the suggested fix - the one they suggested worked perfectly, and since all my pages are in a master page, adding it was dead easy. I'll write the solution up here for those
who might want a quick recap.
The solution to not allowing an event to fire before the page was loaded(and the __EVENTVALIDATION hidden was transmitted to the client) was to simply stop the user from submitting before it was "all there". The guide suggested using a custom control at
the bottom of each page to register some javascript, so that's exactly what I did. Here's my aptly named PreLoadActionStopper:
A small note: I first tried putting it all in the RenderContents of my WebControl - this won't work though because it's too late to register a OnSubmitStatement. It needs to be done in the load of the control instead of the render. I put this into my backend
dll, put the server control just before </form> in my master page and voila, it worked like a charm.
By the way, reproducing the problem is quite easy - just hammer a button on a page. Unless it's the very very last thing that's in the html, chances are you'll manage to hit it before the __EVENTVALIDATION field has been sent. Once you do, you crash(or you
get the above error message, depending). Is there perhaps any way to move the eventvalidation field to the top of the file? This would also be a working fix.
Thanks alot for your help Wim.
Best regards,
Eric Johansson
SYSteam Evolution
www.systeam.se
This has been the most helpful post on this seemingly ubiquitous issue. We were plagued by this error for weeks, and could only stare in helpless horror as the log rolled them in one by one (it wasn't THAT dramatic).
I would like to comment on the custom WebControl code. I thought it was a very nice solution to this problem, but needs correction in one area.
The "preSubmitCommand" variable contains javascript that will return true if the page is completely loaded (line 8). I've found that this ultimately will make client-side validators like the RequiredFieldValidator lose its effectiveness at stopping a POST
command if something didn't pass validation. The javascript there will be tagged onto the WebForm_OnSubmit() method (in my case, at least, to the front), and so the early return will bypass the ValidatorOnSubmit function that calls the client-side validation.
The solution is simple: just change the code to only return false when appropriate.
Please feel free to comment on this if it is at all inaccurate or imprecise.
I've actually run into this problem after I fixed the error. The solution wasn't very hard - I just removed the PreloadActionStopper and looked at the default javascript that's generated for the default onsubmit, and added that to my replacement onsubmit.
Here's a small patch that will enable all validators on the client side aswell:
I would suggest an alternative approach to this. I'm not sure if I would consider it best practice to take that route. Now there's redundancy involved, since the ValidatorOnSubmit() will be called twice. The performance hit may not be worth the time it
takes me to write this post, but that's not the point :)
What do you think of this implementation?
protected override void OnLoad(EventArgs e) {
Page.ClientScript.RegisterHiddenField("PageLoaded", "0");
string scriptCommand = "document.getElementById('PageLoaded').value = '1';";
string preSubmitCommand = @"if(document.getElementById('PageLoaded').value!='1')
{
alert('Please allow the page to fully load before attempting an action.');
return false;
Basically if the page is already loaded, then nothing is returned. It will still return true in the end (so the postback can happen), I'm guessing that's all done behind the scenes by asp.net.
Another interesting question came up about this... Can we be sure that this OnLoad method will be the very last one called? If not, then this control won't be very helpful 100% of the time. The MSDN library states that the Load method is run top-down (meaning that the top-level method is called, then its children, so on), but it doesn't specify the order in which the children will be loaded. I can run traces and such on my code and see that in fact it is the last one ran, but that doesn't mean it's true, ya know?
Just to be safe, I modified the scriptCommand variable to the following:
The down side of this is that it'll only set the value to 1 after everything is rendered, which isn't exactly the same (and could take much longer than necessary), but it gives a little more assurance that the page is indeed loaded. I'd rather not do it
this way, but unless I can find some more convincing evidence that putting this control at the end of the form will make it run last, I think that's what I'll have to do.
EricJohansso...
Member
219 Points
53 Posts
System.ArgumentException EventValidation Exception on long load times
Aug 09, 2007 04:11 PM|LINK
Hi.
I recently wrote a pretty high-intensity(about 200K pageviews/day) site. It worked perfectly in testing, and in the beginning everything was fine. Yesterday though, the ad network that the site is on experienced some problems, resulting in some IE clients(problem did not show up in firefox) getting very, very long load times(my best guess is it's because firefox uses multiple pipes to download content, while many ie clients only use one, so they stalled on the ad content, but I'm merely guessing. This is not the point). I noticed that I started getting alot of ArgumentExceptions in my log, more specifically, this:
Normally, this would be fine - it's an exception thrown when people try to post harmful code in a postback(from what I understand), but in this case, it was being thrown all over the place. From what I've managed to test, the exception also gets thrown if someone tries to use a server control that raises a postback before the page is fully loaded(Finally, I got to the point!).
My question: Why does it do this, and how can I change this behaviour? I'd rather keep enableEventValidation on, since I don't trust the people out there overly much. I can of course catch the exception and ignore it, but this would still mean it's broken, only I won't see it, which I don't want either. Hoping for some help from you folks. :)
Eric Johansson
SYSteam Evolution
www.systeam.se
deblendewim
Contributor
5590 Points
951 Posts
Re: System.ArgumentException EventValidation Exception on long load times
Aug 10, 2007 09:49 AM|LINK
Hi Eric,
I also had this error once ... is it only happening in IE6?
Well, I'm not sure what the exact cause is but you should google for "Invalid postback or callback argument" .... lots of links will show up.
Don't look at the ones saying you should disable the event validation ... that's just ignoring the real cause of the problem.
But I found some more useful links ...
http://communityserver.org/forums/t/466293.aspx : here they talk about that maybe the binding in the load event is the problem, and not putting it in the NOT ISPOSTBACK, they also provide a possible fix
and so on .....
I also think the cause is the databinding in the wrong place .... not specifically double databinding ...
Not much of a solution but I hope it helps ...
Wim
EricJohansso...
Member
219 Points
53 Posts
Re: System.ArgumentException EventValidation Exception on long load times
Aug 10, 2007 03:18 PM|LINK
Hi Wim.
The error occured in IE7, but it was because it halted halfway through loading a page on the ads during the ad networks trouble. My guess is that the bug will occur similarily in FF or IE6 on a sufficiently large webpage.
If I'd been doing databinding on all the pages that displayed the error, then sure, I'd guess is was connected; but I'm not. Most of the pages that displayed the error contains no databinding at all. They do however have some action(button_click, textbox_changed) associated with a server control. If the event triggered before the page had loaded completely, the exception was thrown.
Eric Johansson
SYSteam Evolution
www.systeam.se
deblendewim
Contributor
5590 Points
951 Posts
Re: System.ArgumentException EventValidation Exception on long load times
Aug 10, 2007 04:02 PM|LINK
Hey Eric,
In the link I mentioned above, a guy was had a simular issue.
The error got thrown when his end-users tried to log-in when the login-page isn't fully loaded yet.
Did you check out his workaround on that issue? Maybe it can help you too.
Maybe disabling submit-controls when async postbacks are occuring is a solution? Just brainstorming a bit on my own here (MS dudes, join the club :p)
Here is something about the button disabling (but it's only for the controls on an updatepanel that get triggered I guess ..): http://encosia.com/index.php/2007/01/01/improved-progress-indication-with-aspnet-ajax/
Also, is it possible to replicate the problem in a small working code example, that would be great to test/debug on.
Kind regards,
Wim
EricJohansso...
Member
219 Points
53 Posts
Re: System.ArgumentException EventValidation Exception on long load times
Aug 12, 2007 07:45 PM|LINK
Hi Wim.
I'd like to thank you for sticking in there even when I was to tired to properly read the suggested fix - the one they suggested worked perfectly, and since all my pages are in a master page, adding it was dead easy. I'll write the solution up here for those who might want a quick recap.
The solution to not allowing an event to fire before the page was loaded(and the __EVENTVALIDATION hidden was transmitted to the client) was to simply stop the user from submitting before it was "all there". The guide suggested using a custom control at the bottom of each page to register some javascript, so that's exactly what I did. Here's my aptly named PreLoadActionStopper:
[ToolboxData("<{0}:PreLoadActionStopper runat=server />")] public class PreLoadActionStopper : WebControl { protected override void OnLoad(EventArgs e) { Page.ClientScript.RegisterHiddenField("PageLoaded", "0"); string scriptCommand = "document.getElementById('PageLoaded').value = '1';"; string preSubmitCommand = @"if(document.getElementById('PageLoaded').value=='1') { return true; } alert('Please allow the page to fully load before attempting an action.'); return false;"; Page.ClientScript.RegisterStartupScript(this.GetType(), "onLoad", scriptCommand, true); Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "OnSubmit", preSubmitCommand); base.OnLoad(e); } protected override void RenderContents(HtmlTextWriter output) { } }A small note: I first tried putting it all in the RenderContents of my WebControl - this won't work though because it's too late to register a OnSubmitStatement. It needs to be done in the load of the control instead of the render. I put this into my backend dll, put the server control just before </form> in my master page and voila, it worked like a charm.
By the way, reproducing the problem is quite easy - just hammer a button on a page. Unless it's the very very last thing that's in the html, chances are you'll manage to hit it before the __EVENTVALIDATION field has been sent. Once you do, you crash(or you get the above error message, depending). Is there perhaps any way to move the eventvalidation field to the top of the file? This would also be a working fix.
Thanks alot for your help Wim.
Eric Johansson
SYSteam Evolution
www.systeam.se
DMac
Member
4 Points
2 Posts
Re: System.ArgumentException EventValidation Exception on long load times
Mar 17, 2008 06:10 PM|LINK
This has been the most helpful post on this seemingly ubiquitous issue. We were plagued by this error for weeks, and could only stare in helpless horror as the log rolled them in one by one (it wasn't THAT dramatic).
I would like to comment on the custom WebControl code. I thought it was a very nice solution to this problem, but needs correction in one area.
The "preSubmitCommand" variable contains javascript that will return true if the page is completely loaded (line 8). I've found that this ultimately will make client-side validators like the RequiredFieldValidator lose its effectiveness at stopping a POST command if something didn't pass validation. The javascript there will be tagged onto the WebForm_OnSubmit() method (in my case, at least, to the front), and so the early return will bypass the ValidatorOnSubmit function that calls the client-side validation. The solution is simple: just change the code to only return false when appropriate.
Please feel free to comment on this if it is at all inaccurate or imprecise.
Thanks for the great post, it was a life saver!
EricJohansso...
Member
219 Points
53 Posts
Re: System.ArgumentException EventValidation Exception on long load times
Mar 18, 2008 05:36 PM|LINK
Hi Dmac.
I've actually run into this problem after I fixed the error. The solution wasn't very hard - I just removed the PreloadActionStopper and looked at the default javascript that's generated for the default onsubmit, and added that to my replacement onsubmit. Here's a small patch that will enable all validators on the client side aswell:
protected override void OnLoad(EventArgs e) { Page.ClientScript.RegisterHiddenField("PageLoaded", "0"); string scriptCommand = "document.getElementById('PageLoaded').value = '1';"; string preSubmitCommand = @"if(document.getElementById('PageLoaded').value=='1') { return !(typeof(ValidatorOnSubmit) == ""function"" && ValidatorOnSubmit() == false); } alert('Please allow the page to fully load before attempting an action.'); return false;"; Page.ClientScript.RegisterStartupScript(this.GetType(), "onLoad", scriptCommand, true); Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "OnSubmit", preSubmitCommand); base.OnLoad(e); }Eric Johansson
SYSteam Evolution
www.systeam.se
DMac
Member
4 Points
2 Posts
Re: System.ArgumentException EventValidation Exception on long load times
Mar 18, 2008 11:29 PM|LINK
Hi Eric,
I would suggest an alternative approach to this. I'm not sure if I would consider it best practice to take that route. Now there's redundancy involved, since the ValidatorOnSubmit() will be called twice. The performance hit may not be worth the time it takes me to write this post, but that's not the point :)
What do you think of this implementation?
protected override void OnLoad(EventArgs e) { Page.ClientScript.RegisterHiddenField("PageLoaded", "0"); string scriptCommand = "document.getElementById('PageLoaded').value = '1';"; string preSubmitCommand = @"if(document.getElementById('PageLoaded').value!='1') { alert('Please allow the page to fully load before attempting an action.'); return false;}Basically if the page is already loaded, then nothing is returned. It will still return true in the end (so the postback can happen), I'm guessing that's all done behind the scenes by asp.net.
Another interesting question came up about this... Can we be sure that this OnLoad method will be the very last one called? If not, then this control won't be very helpful 100% of the time. The MSDN library states that the Load method is run top-down (meaning that the top-level method is called, then its children, so on), but it doesn't specify the order in which the children will be loaded. I can run traces and such on my code and see that in fact it is the last one ran, but that doesn't mean it's true, ya know?
Just to be safe, I modified the scriptCommand variable to the following:
The down side of this is that it'll only set the value to 1 after everything is rendered, which isn't exactly the same (and could take much longer than necessary), but it gives a little more assurance that the page is indeed loaded. I'd rather not do it this way, but unless I can find some more convincing evidence that putting this control at the end of the form will make it run last, I think that's what I'll have to do.
Mr Baldman
Member
31 Points
29 Posts
Re: System.ArgumentException EventValidation Exception on long load times
Mar 25, 2008 01:53 PM|LINK
correct me if im wrong (for some situations), but the following code stopped the error happening on my sites...
protected override void Render(HtmlTextWriter writer) { Register(this); base.Render(writer); } private void Register(Control ctrl) { foreach (Control c in ctrl.Controls) Register(c); Page.ClientScript.RegisterForEventValidation(ctrl.UniqueID); }That fix is taken from THIS thread
thanks to retox
s.foschi
Member
7 Points
5 Posts
Re: System.ArgumentException EventValidation Exception on long load times
Apr 25, 2008 01:51 PM|LINK
I got the same error