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

RadGrid Sorting Error

4 Answers 223 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kai
Top achievements
Rank 1
Kai asked on 22 Oct 2009, 08:58 PM
I have a RadGrid with the allow sorting property turned on.  I'm doing a databind to this object in the OnLoad event.  When the page loads up, I can click on the header name to do a sort, but when I click on the down/up arrow, it get an error.  This is what I see in my stack trace.

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

And this is what the description says.
Invalid postback or callback argument. Event validation is enabled using

I'm simply binding my datasource which is a datatable to the datagrid.  I do have the columns set up so that the correct data column in my data table will go into the correct column in the RadGrid object.

Thanks in advance,
Kai Thao

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Oct 2009, 06:16 AM
Hello Kai,

Probably the reason for this error is that when you rebind the grid instance in Page_Load every time, the posted data and viewstate will be lost. As a result, the ID of the sort button is different and when the event is validated there will be no matching unique id and so event validation will fail. Hence, an event is raised for a button that is no longer in the control tree. You can work around this by wrapping your code in the if (!IsPostBack) as shown below:

c#:

protected void Page_Load(object sender, EventArgs e)   
    {   
       if (!IsPostBack)  
       { 
         RadGrid1.DataSource = dt;   
         RadGrid1.DataBind();  
       }          
    }  

Hope this helps..

Princy.

0
Kai
Top achievements
Rank 1
answered on 23 Oct 2009, 01:33 PM
Thanks for the quick replay Princy.  Yes, that was what I had to finally go with.  What I didn't know was that once I did that, then I would need to catch the NeedsDataSource event.  So essentially, this is what I needed to have in my code.

protected void Page_Load(object sender, EventArgs e) 
    if (!IsPostBack) 
    { 
        RadGrid1.DataSource = MyDataTable; 
        RadGrid1.DataBind(); 
    } 
 
protected void dgdSegments_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
    RadGrid1.DataSource = MyDataTable; 

Kai Thao
0
sf
Top achievements
Rank 1
answered on 14 Jan 2011, 06:17 AM
hi Princy
I am having the exact same error, but the solution doesn't help.
at the moment i can only do "<telerik:GridBoundColumn  ShowSortIcon="false"  />"
Any other possible fixes?
It seems that click on the column header (the text) trigers a postback and click on the little arrow trigers a callback.
0
Dinker Batra
Top achievements
Rank 1
answered on 17 Mar 2011, 06:30 PM
Hi Princy, I tried the fix but I am still facing the same problem.
Tags
Grid
Asked by
Kai
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Kai
Top achievements
Rank 1
sf
Top achievements
Rank 1
Dinker Batra
Top achievements
Rank 1
Share this question
or