By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,314 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,314 IT Pros & Developers. It's quick & easy.

"Invalid postback or callback argument"

P: 52
Hi guys,

I want to have a button which opens up a new window when pressed.


Expand|Select|Wrap|Line Numbers
  1. <asp:Button ID="Button1" runat="server" Text="Open new window" />
  2.  
  3. ...
  4.  
  5. Button1.Attributes.Add("OnClick",
  6.                 "window.open(' ... ', null, ' ... ');return false;");
  7.  
But when the button's being clicked on for the first time, nothing would happen. If you click on it again it displays the below error message:


Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> 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.

[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif] Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> 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.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:

[ArgumentException: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> 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.]
System.Web.UI.ClientScriptManager.ValidateEvent(St ring uniqueId, String argument) +8620921
System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +72
System.Web.UI.WebControls.TextBox.LoadPostData(Str ing postDataKey, NameValueCollection postCollection) +34
System.Web.UI.WebControls.TextBox.System.Web.UI.IP ostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +14
System.Web.UI.Page.ProcessPostData(NameValueCollec tion postData, Boolean fBeforeLoad) +346
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1743
[/FONT]




On the other hand if I use a link instead of a button, it would work fine:

Expand|Select|Wrap|Line Numbers
  1. <a href="..." target="_blank" title="Upload" onclick="window.open(this.href, null, ' ... '); return false;">Open new window</a>
I think this might have something to do with the fact that this button is placed inside an asp:UpdatePanel (I'm using Ajax:TabContainer).

Setting EnableEventValidation to false might solve this and I don't mind using links instead of buttons; but does anyone know the cause of this?



Thanks a lot :)
Jan 14 '09 #1
Share this Question
Share on Google+
9 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Where do you see this error?
In the window that the button was clicked or the new popup window?
Jan 14 '09 #2

P: 52
@Frinavale
In the window that the button was clicked; there's no popup window.
Jan 14 '09 #3

P: 40
hi,

use this code in the page_load event,

if(!IsPostBack)
Button1.Attributes.Add("OnClick", "window.open('Default.aspx', null, ' ... ');return false;");

here the 'Default.aspx' is the page i want to be shown in the popup window.
try it.

thanks in advance
blacky
Jan 15 '09 #4

P: 52
@Blacky
Thanks a lot Blacky; I've found out the problem was due to the url of the new window, which I set to something like:
Expand|Select|Wrap|Line Numbers
  1. Default.aspx?parameter=document.getElementByID('TextBox').value
  2.  
In an attempt to make a search button that pops up a new window.....

Anyway, can you point out what I need to do to achieve this?

Many thanks
Jan 15 '09 #5

P: 52
I've googled and found a way to do it using Response.Write().

However it would throw a Sys.WebForms.PageRequestManagerParserErrorExceptio n if I do that. After more googling this seems to be caused by a bug in Ajax, which happens when you have Response.Write inside an UpdatePanel, and it doesn't look like it can be overcome easily.

If anyone knows another way, please help =(

Cheers
Jan 15 '09 #6

Frinavale
Expert Mod 5K+
P: 9,731
Response.Write is not the best way to solve this problem.
When you use it, whatever you add to the Response.Write could appear anywhere in your HTML. For example it could place your output above the <head> section.

This doesn't go over too well with Ajax since only the portion of the page that caused the postback should be updated.

JavaScript is sometimes messed up by Ajax as well...especially after a partial page update. To get around this you should move your code that opens the new window into a JavaScript function and register it with the ScriptManager. You need to indicate that this script has to be loaded every time an asynchronous postback occurs so that it will still work after a partial page update happens. I forget which method does this so you'll have to look into which one will do this for you.
Jan 15 '09 #7

Curtis Rutland
Expert 2.5K+
P: 3,256
Response.Write if used in your codebehind, as far as I know, will almost always result in writing the content before any HTML tags, since the processing happens before the page is sent back to the client.

The only time Response.Write is really good is if you are using inline code.
Jan 15 '09 #8

P: 52
I don't quite understand how to use ScriptManager.

When do I need to register the script with ScriptManager.RegisterClientScriptBlock, when do I call the registered script, and how do I send parameters in?
Jan 15 '09 #9

Frinavale
Expert Mod 5K+
P: 9,731
Here are so more details on how to use the ScriptManager. I think you'll be most interested in how to use the RegisterClientScriptInclude method.
Jan 16 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.