I have a simple RadGrid, AllowPaging="true" and data is bound via OnNeedDataSource. The following relevant template to describe the problem is:
<
telerik:GridTemplateColumn
HeaderText
=
"Actions"
>
<
ItemStyle
Wrap
=
"false"
/>
<
ItemTemplate
>
<
asp:Button
ID
=
"uxDeleteDeployment"
runat
=
"server"
CommandName='<%# Eval("deploymentId") %>' ToolTip="Delete deployment" AlternateText="Delete deployment" ImageUrl="/_layouts/images/delete.gif" ImageAlign="AbsMiddle" Visible="false" OnClick="uxDeleteDeployment_Click" OnClientClick='<%# JsEncoder.Format(@"alert(""{0}""); return true", Eval("deploymentId")) %>' />
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
The OnClientClick code alert the value passed to it (in this case it is just a deploymentId -- the same binding that is used with CommandName). The importance of this will be explained below. Also note that I do not set CommandArgument so it will default to the "data key" which is the deploymentId.
In the uxDeleteDeployment_Click there is the following code:
var button = (Button)_sender;
throw
new
InvalidOperationException(
"Foo: "
+ button.CommandName +
"|"
+ button.CommandArgument);
Now, there are the symptoms:
When an item on the FIRST PAGE is clicked the confirm dialog will show X (X is a particular but arbitrary deployment ID for the item) and the exception thrown on on the post-back is "Foo: X|X" -- this is correct behavior.
Now, when the SECOND PAGE is paged to and the button is clicked the confirm dialog will show X (X is a particular but arbitrary deployment ID for the item). However, the exception thrown on the post-back is "Foo: Y|Y" (note Y and not X!!!) where Y is the deploymentId of the item with the SAME PAGE POSITION but on the FIRST PAGE. For instance, Y is the deploymentId of Item #3 from the data-source if Item #13 (#3 in list on the SECOND PAGE) is clicked -- this is not correct behavior.
Additionally,
If the page-size is changed (default is 10) to 20 and item #13 is clicked, the OnClick callback will not be invoked -- rather the page will be refresh to show only the FIRST PAGE (page size of 10) but leaves "20" in the page-size field -- this is not correct behavior.
Other notes:
- BOTH issues do not exist if paging is disabled.
- BOTH issues do not occur if manually intercepting the client click and invoking an alternate post-back. (The issue seems to be entirely contained with the post-back of the RadGrid itself.)
- Using version 2011.1.413.35 (latest as of today) but exact same problems(s) on 2010 Q3
ViewStateMode does not change the symptoms/behavior. (ViewState is enabled because filtering is used; disabling the ViewState was just for a test and it had no noticeable effect.)
CommandName/CommandArgument have this same incorrect behavior inside of an ItemCommand for the grid (in the case above I discuss it in context of an OnClick applied to the individual button). In the case of ItemCommand the code 'e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["deploymentId"];' results in the same value as CommandArgument (which is wrong).
Removing the client-side event handler does not correct the behavior.
- The Eval is bound correctly per (as shown in the JS alert) but the values sent to the post-back callback were wrong.
- No AJAX is used -- all post-backs are normal HTTP. There are no additional/secondary post-backs that occur (verified with FireBug).
- The RadGrid is running in a UserControl a SharePoint 2010 environment. This should not matter.
- (The text formatting of this post input area changed when a new item was added to the list and some of the text now looks ugly.)
I have looked through the Demos and I can not find a case covering this use-case -- a custom OnClick/ItemCommand of a Particular Item being manually handled from the non-first page of a paged RadGrid control (The "Selected" demos do not count because the behavior is internal to the RadGrid control and not a manual event). It would be nice to see a test-case demonstrating this scenario as then I could look for fault elsewhere. However, as it is now, I cannot find this example demonstrated.
Any suggestions/fixes are appreciated.
Because of this error I must now go and validate all existing code to ensure this issue is not present elsewhere. Not a good feeling.