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

Command Item and Invalid postback or callback argument

2 Answers 227 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Khaled
Top achievements
Rank 1
Khaled asked on 23 Jun 2009, 02:37 AM
Hi All

I am new to telerik amazing controls,and that is the first time for me to use the RadGrid control,In my page i changed the property CommandItemDisplay from 'None' to 'Bottom' to enable the enduser to add new records within the grid as shown on this online demo.
the datasource i used is a method that returns a Datatable.so i bind it to the grid in the page load event as the following
    protected void Page_Load(object sender, EventArgs e)  
    {  
        GridSubscribers.DataSource = SubscribersManagement.GetSubcribersByISP(ISP);  
        GridSubscribers.DataBind();  
    } 
The table i bind to is empty,so when i click the add button in the command row and i used the code exactly provided in the demo for the itemCommand event,sometimes it opens the inster template but most of the time it fires an exception of "Invalid postback or callback argument.",What could be the reason behind that and how can i solve it?? i use Asp.Net 2.0 & Rad controls 2008 Q1.

Thanks
 .

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Jun 2009, 11:32 AM
Hello Khaled,

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 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)  
       { 
         GridSubscribers.DataSource = SubscribersManagement.GetSubcribersByISP(ISP);   
         GridSubscribers.DataBind();  
       }          
    }  

Thanks

Princy.

0
Khaled
Top achievements
Rank 1
answered on 25 Jun 2009, 06:43 AM
Thanx Princy for reply,but i already did what u told me to and still the same.....i tried to put a button outside the grid,and use the window to insert or edit,but i have a problem with the window when i close it,,it does not refresh the grid,i followed the demo and instructions but it gives me a java script error on line number 4 in the following function??? 
        function CloseAndRebind(args)  
        {  
            GetRadWindow().Close();  
            GetRadWindow().BrowserWindow.refreshGrid(args);  
        } 
Is there any other way to do what i want easier than the approach used on the demo ?

Best Regards
Tags
Grid
Asked by
Khaled
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Khaled
Top achievements
Rank 1
Share this question
or