We help IT Professionals succeed at work.

Invalid postback

mattfox77
mattfox77 asked
on
Medium Priority
981 Views
Last Modified: 2013-12-17
I have a C# asp.Net page - default.aspx -  that receives a user's credentials, retrieves the user's data from the database,  and generates a datalist containing a button for each item in the datalist.  
clicking the datalist item button calls another page - launch.aspx - that displays different user data.
I have a button - btnUser - on default.aspx with an btnUser_Click method that defines the datalist datasource and binds the datalist.
When I click btnUser The datalist populates with several items and buttons.  the item buttons work as expected,  calling launch.aspx and passing data
But,  when I try to call btnUser_Click from the page load using  
  btnUser_Click(btnUser, null);

the datalists populate as before ,  but when I click any item button I receive this error
Server Error in '/' Application.
--------------------------------------------------------------------------------

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) +8620921
   System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +72
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +35
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053

protected void Page_Load(object sender, EventArgs e)
        {
            //instantiate Variables as null or 0
            ActID = null;
        int iStatus = 0;
        Int32 iCompletionStatus = 0;
        Int32 iSuccessStatus = 0;
                
        //capture values if passed otherwise set to debug values
        try { UserID = Request.Params["User"]; }
        catch { UserID = "debug"; }
        try { UserPass = Request.Params["Pass"]; }
        catch { UserPass = "debug"; }
        //Debug - Set variables to Labels
        txtUser.Text = UserID;
        lblUserID.Text = UserID;
        lblPass.Text = UserPass;
            //Set User Credentials to hidden fields used later in ItemCommands below
        hfUserPass.Value = UserPass;
        hfUserID.Value = UserID;
       //Get User's Activities if UserID not null
        if (UserID != null)
        {
            if (UserID != "debug")
            {
                btnUser_Click(btnUser, null);
            }
        }
       
        }
 
        
            
        protected void btnUser_Click(object sender, EventArgs e)
        {
            //Set UserID on Button click and copy to hiddenfield
            UserID = txtUser.Text;
            lblUser.Text = UserID;
            hfUserID.Value = UserID;
            //Call UserBLL Class Method to retrieve User data
            UserBLL userLogic = new UserBLL();
           //Bind User Registered CBTs to DataList
            UserBLL regLogic = new UserBLL();
            dlRegActivities.DataSource = regLogic.GetUserRegisteredCBTs(UserID);
            dlRegActivities.DataBind();
            //Debug - Bind User Registered CBTs to Gridview
            gvRegCBTs.DataSource = regLogic.GetUserRegisteredCBTs(UserID);
            gvRegCBTs.DataBind();
            //Setup the DataLists for each certification to show user's status for that certification
            UserBLL certLogic = new UserBLL();
            dlCertBank.DataSource = certLogic.GetCurrentUserAttemptByActCode(UserID, "SH_SFB0100W");
            dlCertBank.DataBind();
            dlCertFair.DataSource = certLogic.GetCurrentUserAttemptByActCode(UserID, "SH_SFB0200W");
            dlCertFair.DataBind();
            dlCertFlood.DataSource = certLogic.GetCurrentUserAttemptByActCode(UserID, "SH_SFB0400W");
            dlCertFlood.DataBind();
            dlCertPrivacy.DataSource = certLogic.GetCurrentUserAttemptByActCode(UserID, "BE_SFB5539W");
            dlCertPrivacy.DataBind();
            dlCertTruth.DataSource = certLogic.GetCurrentUserAttemptByActCode(UserID, "SH_SFB1100W");
            dlCertTruth.DataBind();
        }
 
// Datalist Item button ItemCommand code:
protected void dlRegActivities_ItemCommand(object source, DataListCommandEventArgs e)
        {
            //On click of Launch button in datatlist ActID is set to Activity_PK and UserD and UserPass are reset to hiddenfied value set earlier
            if (e.CommandName == "LaunchActivity")
            {
                ActID = e.CommandArgument.ToString();
                lblActID.Text = ActID;
                UserID = hfUserID.Value;
                UserPass = hfUserPass.Value;
                //debug - set lblUSerID to verify UserID is properly set
                lblUserID.Text = UserID;
                //Transfer to Launch Page and pass UserID and ActID as Query Parameters
                Server.Transfer("Launch.aspx?UserID=" + UserID + "&Pass=" + UserPass + "&ActID=" + ActID);
            }
        }

Open in new window

Comment
Watch Question

Anurag ThakurTechnical Manager

Commented:
you looking in the wrong area
dont look for <pages enableEventValidation="true"/> errro in the .cs code
look for the error in the aspx part

this error generally comes when you are using updatepanels
in the web.config file, under pages add these attributes

<pages validateRequest="false" enableEventValidation="false">
Technical Manager
Commented:
never do that .... its not safe and thats not a solution as the aspx page is not well formed

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
ragi0017, i agree.  but i ran into similar sort of problems and this workaround fixed it. what is the cause of this issue and why the workaround is not safe, as most of the forum suggest this?

Author

Commented:
I would prefer to have a safe, well - formed page, so attached is the default.aspx page and the .cs in a zip as txt files.  Can you see what's not well - formed about it?  Is this a small fix or require a complete re-write?

Default.zip
Anurag ThakurTechnical Manager

Commented:
sorry but i dont have the time to go through the code....
please look in the aspx page... and see if any td or tr is still open

Author

Commented:
You were right - there's a nother problem that's deeper than just a postback.  I added the pages setting and it cleared the error,  exposing another problem.  So I am rewriting the page,  hopefully with better form.  Thanks for not letting me slide with a bad practice.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.