?
Solved

Invalid postback

Posted on 2009-02-14
7
Medium Priority
?
925 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

0
Comment
Question by:mattfox77
  • 3
  • 2
  • 2
7 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 23643607
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
0
 
LVL 12

Expert Comment

by:CB_Thirumalai
ID: 23643689
in the web.config file, under pages add these attributes

<pages validateRequest="false" enableEventValidation="false">
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 1500 total points
ID: 23643730
never do that .... its not safe and thats not a solution as the aspx page is not well formed
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 12

Expert Comment

by:CB_Thirumalai
ID: 23643799
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?
0
 
LVL 1

Author Comment

by:mattfox77
ID: 23645566
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
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 23647229
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
0
 
LVL 1

Author Closing Comment

by:mattfox77
ID: 31546996
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.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question