This is a migrated thread and some comments may be shown as answers.

Invalid postback or callback argument using NeedDataSource

1 Answer 335 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 17 Jan 2013, 04:14 PM
I'm creating a properties panel with the RadGrid, allowing the properties of a column of a different grid to be viewed/edited.

However, when I try to edit a row, I'm seeing this error:

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.
   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.ImageButton.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.WebControls.ImageButton.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)

I've been looking for more information and I did see this thread:  http://www.telerik.com/community/forums/aspnet-ajax/grid/telerik-radgrid-invalid-postback-or-callback-argument.aspx

I am using Advanced DataBinding, utilizing the NeedDataSource event so the solution there doesn't seem applicable.  I do have ajax enabled, utilizing the AjaxManagerProxy on the page for the grid.  At load, the NeedDataSource will bind to an empty arraylist.  If a user clicks the column of a different grid, I utilize an ajax request to populate the datasource of this grid.  I then DataBind().  This works fine.

Once I click the "edit" button on the grid row, that is when this issue arises.  The edit button is within the radgrid that's erroring but maybe due to my process it's not "the control that originally rendered" the edit button?

Below are some code snippets.  DisplayColumnProperties is what the ajax request comes back and ultimately calls.  It's not applicable to clicking the "edit" button, but it is a special case so I included it.

public void DisplayColumnProperties(string uniqueName)
{
    if (CustomReport != null && !string.IsNullOrEmpty(uniqueName))
    {
        GridColumnProperties_SetDataSource(uniqueName);
        gridColumnProperties.DataBind();
    }          
}
 
protected void GridColumnProperties_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    string columnName = (string)this.ViewState["columnName"];
    if (!string.IsNullOrEmpty(columnName))
    {
        GridColumnProperties_SetDataSource(columnName);
    } else {
        gridColumnProperties.DataSource = new ArrayList();
    }
}

GridColumnProperties_SetDataSource does not DataBind() as I think some might ask.  It builds up a view model object dictionary and sets that to the datasource as well as setting the columnName in the viewstate.

Any insight is appreciated.  Thank you.

1 Answer, 1 is accepted

Sort by
0
Rob
Top achievements
Rank 1
answered on 17 Jan 2013, 05:43 PM
Finding my own problems and solutions is pretty rewarding I guess.  I don't know if it's just the break at writing up a post, but posting here often lets me then turn around and fix issues.

First, a better way to do the ajax, which then will trigger the NeedDataSource
public void DisplayColumnProperties(string uniqueName)
{
    if (CustomReport != null && !string.IsNullOrEmpty(uniqueName))
    {
        this.ViewState["columnName"] = uniqueName;
        gridColumnProperties.Rebind();
    }          
}

I still was having problems so I enabled the ViewState of the grid.  That worked, but then I was having problems with dynamic controls within my grid.
System.Web.HttpException (0x80004005): Failed to load viewstate.
The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.
For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

That's because I didn't follow:  http://www.telerik.com/help/aspnet-ajax/grid-distinguish-differences-between-itemcreated-itemdatabound.html .  Moving my dynamic controls to an OnItemCreated event solved the problem there as well.
Tags
Grid
Asked by
Rob
Top achievements
Rank 1
Answers by
Rob
Top achievements
Rank 1
Share this question
or