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

OnCommand not firing with CommandItemTemplate

6 Answers 420 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 2
Stephen asked on 25 Jun 2009, 03:07 AM
I had a grid setup to display some data.  When an insert occurred, I wanted to display a message so I subscribed to the OnCommand client event.  This worked well and was fired when the insert command item was clicked.

I needed to customise the command item so set up a CommandItemTemplate as follows

            <CommandItemTemplate> 
                <table width="100%" style="margin: 5px">  
                    <td align="left">  
                        <span class="GridTitle">Accounts</span> 
                    </td> 
                    <td align="right">  
                        <asp:LinkButton runat="server" class="GridCommandButtonText" CommandName="InitInsert">  
                            <img style="border:0px;vertical-align:middle;" alt="Insert" src='<%= ToAbsoluteURL("~/Images/Add_24.png") %>' />&nbsp;&nbsp;Add new account  
                        </asp:LinkButton>&nbsp;&nbsp;&nbsp;&nbsp;  
                        <asp:LinkButton runat="server" class="GridCommandButtonText" CommandName="RebindGrid">  
                            <img style="border:0px;vertical-align:middle;" alt="Refresh" src='<%= ToAbsoluteURL("~/Images/Refresh_24.png") %>' />&nbsp;&nbsp;Refresh account list  
                        </asp:LinkButton>&nbsp;&nbsp;&nbsp;  
                    </td> 
                </table> 
            </CommandItemTemplate> 
 

This displayed as I wanted it to, however the insert and refresh buttons don't fire the client event, they only fire the server event.  Is there a way that these can conform to the standard process and call the OnCommand event or is this a bug. 

I am running the the latest version of RadControls.

Thanks

Stephen

6 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 25 Jun 2009, 06:26 AM

Hello Stephen,

Generally every button control placed inside RadGrid CommandItemTemplate with at least CommandName set will trigger ItemCommand event of the grid control.

Regarding client-side events I do not see in your code any client event listener attached.

I will suggest you to set ID's of the LinkButton controls. You can also use ImageButton instead of a LinkButton in this case.

You find example of how to customize CommandItemTemplate on the following online demo:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/commanditem/defaultcs.aspx

Greetings,
Nikolay
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Stephen
Top achievements
Rank 2
answered on 25 Jun 2009, 08:32 AM
Hi Nikolay

Thanks for the answer.  I had looked at that example but that doesn't include the client side events. 

If I can clarify what you are implying from your second paragraph, that when using the template the grids client-side "OnCommand" event is not automatically fired for the buttons as it is for the automatically generated command buttons (ie without the template).  If I want a javascript event to be called then I need to wire it up myself.

Am I correct in understanding what you are saying?  Is there any way I can wire up the link buttons to fire the OnCommand event (I also have command buttons on the rows and would prefer it was all handled consistently if possible)?

Thanks

Stephen
0
Nikolay Rusev
Telerik team
answered on 29 Jun 2009, 09:19 AM
Hello Stephen,

For your convenience I've prepared sample application demonstrating that RadGrid fires custom commands, triggered by button within CommandItemTemplate.
Please find the attachment.

Sincerely yours,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Stephen
Top achievements
Rank 2
answered on 29 Jun 2009, 09:20 PM
Hi Nikolay

Thanks for the example.  In yor example, the javascript events are firing manually, apart from the Grid's OnCommand javascript event.  My query was whether there was a way to have the OnCommand javascript event of the grid handle the custom commands in the CommandItemTemplate.  I am surmising from your example that this must be done manually for each control rather than being handled consistently with the OnCommand javascript event as the default command layout is done.

Thanks

Stephen
0
Accepted
Nikolay Rusev
Telerik team
answered on 02 Jul 2009, 01:39 PM
Hello Stephen,

Generally to fire client OnCommand you must attached client script to your Button control that will trigger OnCommand.
You can find more information on the link below:
http://www.telerik.com/help/aspnet-ajax/grid_firecommand.html

Regards,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Stephen
Top achievements
Rank 2
answered on 02 Jul 2009, 11:12 PM
Thanks Nikolay.  That was the information I needed.
Tags
Grid
Asked by
Stephen
Top achievements
Rank 2
Answers by
Nikolay Rusev
Telerik team
Stephen
Top achievements
Rank 2
Share this question
or