RadGrid does not fire postback on ItemCommand events

I am currently evaluating some RAD elements from Telerik, I am currently experimenting with RadGrid.

So I have my grid control and client side binding enabled for Ajax support. I have created a corresponding WCF webservice for collecting data etc. Everything works very well including paging, etc. Now I wanted to have a column of buttons to remove some items. I have registered the grid's OnItemCommand event and have injected 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 corresponding button on the grid row, the event is not fired, basically no postback to the server is done. The solution I found is to add " EnablePostBackOnRowClick=true

" to the ClientSettings, but this will trigger a postback for every row click, which is not really required.

Is there a better way to implement this or can anyone suggest what the problem might be?

thank

+2


source to share


5 answers


As far as I think this is impossible, please answer from the Telerik forum .



+2


source


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

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

An example of binding to OnCommand and Row DataBound:
<ClientSettings> <ClientEvents OnCommand="Grid_Command" OnRowDataBound="Grid_RowDataBound" /> </ClientSettings>

then in your javascript enclosed in a rad code block you 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
    // ... //
 }

      

`

+2


source


I realize this is ancient, but it still shows up in google results. Now there is a solution, maybe others ...

You can achieve postback with 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>

      

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

+1


source


I had the same problem with telerik control. I solved this problem by recreating the control from scratch with a new name and then rebuilding my structure.

Hope it helps

0


source


RegisterWithScriptManager = "false" might also work.

0


source







All Articles