RadGrid not firing postback on ItemCommand events

29.9k Views Asked by At

I'm currently evaluating some RAD controls from Telerik, just right now I'm experimenting with the RadGrid.

So I have my grid control and enabled client-side binding for having Ajax support. I created an appropriate WCF webservice for fetching the data etc. Everything works really good, including paging etc. Now I wanted to have a button column for deleting some items. I registered the OnItemCommand event of the grid and implemented it accordingly on the server-side. My ASPx code looks like this:

<telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="True"
    AutoGenerateColumns="False" GridLines="None"
    OnItemCommand="RadGrid1_ItemCommand">
    <MasterTableView DataKeyNames="Id" ClientDataKeyNames="Id">
        <Columns>
            <telerik:GridBoundColumn DataField="Firstname" HeaderText="Firstname" DataType="System.String">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Lastname" HeaderText="Lastname" DataType="System.String">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Age" HeaderText="Age" DataType="System.Int32">
            </telerik:GridBoundColumn>
            <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"
                ButtonType="ImageButton">
            </telerik:GridButtonColumn>
        </Columns>
        <PagerStyle Mode="Slider" />
    </MasterTableView>
    <ClientSettings>
        <DataBinding SelectMethod="GetSampleData" Location="Webservice/GridData.svc" SortParameterType="String">
        </DataBinding>
    </ClientSettings>
</telerik:RadGrid>

However when clicking on the appropriate button on a grid row the event isn't fired, basically no postback to the server is being done. A solution I found is to add the "EnablePostBackOnRowClick=true" to the ClientSettings, but this would cause a postback on each click on a row, which is not really desired.

Is there a better way to realizing this or does anybody have a hint what could be the problem??

Thx

5

There are 5 best solutions below

0
On BEST ANSWER

As far as it seems this is not possible given the answer from the Telerik forum.

0
On

I realize this is ancient, but it still shows up high in Google results. There is now a solution to this, maybe others as well...

You can achieve a postback by using a template column

<telerik:GridTemplateColumn UniqueName="myuniquename">
<ItemTemplate>
    <telerik:RadButton ID="RadButton1" runat="server" ButtonType="StandardButton" AutoPostBack="true" CommandName="MyCommand" UseSubmitBehavior="false" Text="Button Text" />
</ItemTemplate>
</telerik:GridTemplateColumn>

Although I'm not sure if you need the "UseSubmitBehavior" property.

0
On

you need to handle the client "OnCommand" event, or more appropriately use the client "RowDataBound" command. In the RowDataBound command you can find your rad button and attach an event to it.

The only other way to do this is to handle the client "onclicking" event from the button itself.

Example of binding to the OnCommand and Row DataBound:
<ClientSettings> <ClientEvents OnCommand="Grid_Command" OnRowDataBound="Grid_RowDataBound" /> </ClientSettings> then in your javascript wrapped in a rad code block have the following methods:

<script type="javascript">
function Grid_RowDataBound(sender, args) {
    var item = args.get_item();
    var data = args.get_dataItem();
    var btn = $find('DeleteColumn');
    btn.add_clicking(delegate); // where delegate is the function you provide for the click
    // ... //
 }

`

0
On

RegisterWithScriptManager="false" this may work as well..

0
On

I had the same problem with telerik controls. I solved this problem by recreating the Control from zero with a new name, then rebuilding my structure.

Hope it helps