Tech Off Thread

19 posts

Invalid postback or callback argument. Wants event validation enabled.

Back to Forum: Tech Off
  • User profile image
    qwert231

    I get this on a button postback:

    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.
    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(String uniqueId, String argument) +2080188
       System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +106
       System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +32
       System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33



    >>> What does thsi all mean? Event Validation? I've had validation working no problem. I'm writing VB .Net 1.1 code, but .Net 2.0 is running ASP .Net, so, is this a compatibility issue? Don't know what steps to take next for this type of issue.

  • User profile image
    footballism

        I've encountered this problem before, the reason for it is that the data posted back to the sever contains some client side scripting code, and this will lead to some kinda security preach, so by default, the enableEventValidation is set to true.

    Sheva

  • User profile image
    qwert231

    Well... it's an ImageButton in a TemplateColumn in a datagrid in a TemplateColumn of a datagrid. That's right, it's a button in a column of a datagrid, that is a child of a parent datagrid.

    This was working. That's why I'm wondering if it's a .Net 2.0 thing. And what else can I do about it. It's a basic datagrid command button.

  • User profile image
    qwert231

    So I still don't know about this. Any ideas?

  • User profile image
    qwert231

    I added both those statements.
    In my aspx Page tag:
     EnableEventValidation="true"

    In my web.config:
    <pages enableEventValidation="true"/>

    I still get the same error message. THIS WAS WORKING! PLEASE, what has happened that this button doesn't work?

    Here's a link to the page:
    http://www.theimageconnection.com/beta/icuser/bskt_list.aspx?Session=121873

    When you remove an item (not an image) I get the error.

  • User profile image
    Sven Groot

    It's something that changed between 1.x and 2.0. 1.x didn't have event validation (it had request validation, which checked if the postback didn't contain html tags etc., but that's not the same thing). I ran into the same problem when upgrading a site and was unable to solve it. I just disabled event validation (<pages enableEventValidation="false" />) and it worked, which isn't perhaps the best solution (event validation should work I think) but it does get the job done.

    EDIT: There's some info about it here: http://forums.asp.net/1064482/ShowPost.aspx, they seem to talk about the RC but I assume it still applies to RTM.

  • User profile image
    qwert231

    I had a Me.DataBind in the Page Load, and it wasn't nested in the If Not Page.IsPostBack, so every time the page was called or did a Postback, everything was DataBound.

    This post: http://forums.asp.net/2/1064482/ShowPost.aspx#1064482

    showed me that in .Net 2.0 that changes the names of controls embedded in DataGrids/Lists on DataBind. Thus it was an unknown control as far as the code was concerned.

  • User profile image
    gingerbbm

    Thanks for this thread. I had the same problem and once I put my data binding into a "!IsPostBack" block everything worked fine.

    Cheers
    Stuart

  • User profile image
    anil2082

    I had the same problem...
    and moving the code block for binding the gridview to the !IsPostBack solved the problem.

    Thanks....

  • User profile image
    Vivekniceguy

    anil2082 said:
    I had the same problem...
    and moving the code block for binding the gridview to the !IsPostBack solved the problem.

    Thanks....

    Just add this to your web config and make pages..like ErrorPage.aspx , and see you will control this error by making your custom control error.

    <system.web>

        <customErrors defaultRedirect="ErrorPage.aspx" mode="On">

              <error statusCode="500" redirect="servererror.aspx" />

              <error statusCode="404" redirect="filenotfound.aspx" />

             <error statusCode="403" redirect="AccessDenied.aspx" />

      </customErrors>

    <system.web>

  • User profile image
    cosmicice

    qwert231 said:
    I had a Me.DataBind in the Page Load, and it wasn't nested in the If Not Page.IsPostBack, so every time the page was called or did a Postback, everything was DataBound.

    This post: http://forums.asp.net/2/1064482/ShowPost.aspx#1064482

    showed me that in .Net 2.0 that changes the names of controls embedded in DataGrids/Lists on DataBind. Thus it was an unknown control as far as the code was concerned.

    I just created this account to say "Thanks". if (!Page.IsPostBack) checking for databind really worked.

  • User profile image
    Shimi Weitzhandler

    qwert231 said:
    I had a Me.DataBind in the Page Load, and it wasn't nested in the If Not Page.IsPostBack, so every time the page was called or did a Postback, everything was DataBound.

    This post: http://forums.asp.net/2/1064482/ShowPost.aspx#1064482

    showed me that in .Net 2.0 that changes the names of controls embedded in DataGrids/Lists on DataBind. Thus it was an unknown control as far as the code was concerned.

    Thanks man!

    I had exactly the same issue!

    That was so frustrating finding that the problem was this stupid if(!IsPostBack) I believe you had the same pain....

    lol

  • User profile image
    Surendran​Anthony

    Thanks Anil. Moving the grid binding code inside !IsPostback solved the problem for me.

  • User profile image
    motto

    @qwert231: Thanks so much for mentioning the invalid DataBind on Postbacks. I was going mad about the same fact "THIS WAS WORKING" Smiley

  • User profile image
    MarcosV

    I had the same problem, I'm using a GridView and I have a TemplateColumn with a ImageButton Like this:

    <asp:TemplateColumn Width="30">
        <ItemTemplate>
    
            <asp:ImageButton ID="btnEdit"
                                       runat="server"
                                       ImageUrl="~/Img/16x16/page_white_edit.png"
                                       ToolTip="Edit"
                                       AlternateText="Edit"
                                       CausesValidation="false"
                                       OnCommand="btnEdit_Command"
                                       CommandArgument="<%# Eval('MyIdField') %>" />
    
        </ItemTemplate>
    
    </asp:TemplateColumn>

    Solution:

    Create a property in the page or User Control (in my case):

            public string IdField
            {
                get { return idField; }
                set { idField = value; }
            }

    And change the parameters in CommandArgument to this:

    CommandArgument="<%# Eval(IdField) %>"

    If you are creating a User Control you need to add this in the aspx:

        <myUserControls:UserControl ID="myUserControl"
                                      runat="server"
                                      IdField="myId" />

    If your are creating a page, you can set the value in the code behind.

    Hope it helps,

  • User profile image
    Mitul

    It works.  I had Page.DataBind in Page.IsPostback = True and it was done on all postback.  I used to databind everything even things I didn't used.  Removing it and placing in correct location solved the problem instantly.

     

  • User profile image
    Sahaj

    Thank  you so much... it works.... binging logic in if not isPostBack then.... Thank you so much again....

  • User profile image
    Sahaj

    @gingerbbm: thanks

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.