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

Radgrid itemcommand not firing for ButtonType="ImageButton"

28 Answers 1073 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 25 Feb 2011, 01:18 PM
I have a radgrid, that's populated in exactly the same way as the one from this demo:

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

So it's populated from an IList kept in session (which in turn is populated when items are dragged into my grid from another grid). The only difference being, my grid isn't populated with onneeddatasource, it's simply bound after some code beind processing of the IList on drop.

This all works fine and I can populate the grid with drag n drop.

I've got a Gridbutton:

<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"></telerik:GridButtonColumn>

On the grid at the moment, I handle the onitemcommand and/or the ondeletecommand for the user clicking this button. If the user clicks the button, this works fine, the itemcommand events fire as expected and I hit breakpoints in the code behind.

If I simply add:

ButtonType="ImageButton"

To the button to display it as an image, rather than as text, I no longer hit any itemcommand events on postback when I click the imagebutton. The button simply posts back and doesn't fire the events it should.

This is the only difference, image rather than text. I'm using Q3 2010.

28 Answers, 1 is accepted

Sort by
0
Matthew
Top achievements
Rank 1
answered on 28 Feb 2011, 11:23 AM
*Bump*

I've found other threads where people have this problem with no itemcommand firing for image buttons, but no fix...
0
Matthew
Top achievements
Rank 1
answered on 28 Feb 2011, 06:27 PM
Any help Telerik?
0
Mike
Top achievements
Rank 2
answered on 01 Mar 2011, 02:13 PM
I am having the same issue here as well. When I change the existing ImageButtons to normal Buttons the item commands execute like Edit, Delete, Update, Insert and Cancel, but when making them an ImageButton again, they just do nothing. Please fix this problem asap as I have many many grids that utilize image buttons as I am sure others do as well. I am working with a NestedView in case you need to know. This problem has only happened in the last update that I can see.
0
Ryan
Top achievements
Rank 1
answered on 01 Mar 2011, 04:32 PM
I am also having this same issue and have been struggling with it for days. I am at the point now where I am abandoning the radgrid because I need to get this working for my client. Any help would be greatly appreciated.
0
Mike
Top achievements
Rank 2
answered on 02 Mar 2011, 01:42 AM
I just tried this in my code behind and all of a sudden the image buttons are working and the nested view grids are working as they should be:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            RadGrid.DataBind();
        }

    }

this may help someone :)
0
Matthew
Top achievements
Rank 1
answered on 02 Mar 2011, 10:14 AM
In mine I've a function called 'BindGrids' which does some processing on the ILists to be bound to the grid, then does a databind, and I call this function in the Page_Load event, but unfortunatly it still doesn't work with imagebuttons. This also gets called (after some list processing logic) on my 'RowDrop' event when dragging/dropping.

I've just tried updating to the latest version of Q3, and I've still got the issue.
0
Pavel
Telerik team
answered on 03 Mar 2011, 02:09 PM
Hello guys,

I am not able to reproduce the problem in a simple test page with our latest release. Please find attached the sample I created for testing. Take a look at it and let me know what is needed to reproduce the undesired behavior.

Greetings,
Pavel
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Matthew
Top achievements
Rank 1
answered on 10 Mar 2011, 06:46 PM
Simple to reproduce with your sample, change the page_load method to:

protected void Page_Load(object sender, EventArgs e)
{
    //RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
    RadGrid1.ItemCommand += new GridCommandEventHandler(RadGrid1_ItemCommand);
    RadGrid1.DataSource = new Object[] { "1", "2" };
    RadGrid1.DataBind();
}

You'll see the item command event no longer fires. If you remove:

ButtonType="ImageButton"

The ItemCommand event will fire.
0
Matthew
Top achievements
Rank 1
answered on 10 Mar 2011, 07:08 PM
Right, this problem also occurs if you use a GridTemplateColumn instead. Imagebuttons inside the template colum with 'CommandName' attributes arn't triggering itemcommand for the radgrid, but linkbuttons are.

However, I've found a workaround. Using the new RadButton control in Q3, inside a GridTemplateColumn. So, somthing along these lines:

<telerik:GridTemplateColumn UniqueName="MyTemplateColumn">
<ItemTemplate  
      <telerik:RadButton ID="btnBgrImg1" CommandName="Delete" runat="server" Width="20px" Height="20px" style="vertical-align:top;" ToolTip="Remove">
   <Image ImageUrl="~/Images/Buttons/20x20/Close_icon.png" IsBackgroundImage="true" />                                             
</telerik:RadButton  
</ItemTemplate>                        
</telerik:GridTemplateColumn>
0
Pavel
Telerik team
answered on 16 Mar 2011, 08:05 AM
Hello Matthew,

I am attaching a test page in which both approaches work. Could you let me know if they work for you as well?

Regards,
Pavel
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Chris
Top achievements
Rank 1
answered on 19 Jul 2011, 08:32 PM

I'm having the same problems.

In both of your examples you are always using

CommandName="Delete"


I create a grid from code behind

 

//up

 

bcolbtn =

new GridButtonColumn();

 

RadGrid1.MasterTableView.Columns.Add(bcolbtn);

bcolbtn.UniqueName =

"SelectColumnUp";

 

bcolbtn.CommandName =

"SelectUp";

 

bcolbtn.Text =

"Up";

 

bcolbtn.ImageUrl =

"~/images/ButtonUpArrow.png";

 

bcolbtn.ButtonType =

GridButtonColumnType.ImageButton;

 

bcolbtn.ItemStyle.HorizontalAlign =

HorizontalAlign.Center;

 

bcolbtn.HeaderStyle.Width =

Unit.Pixel(30);

 

 

//down

 

bcolbtn =

new GridButtonColumn();

 

RadGrid1.MasterTableView.Columns.Add(bcolbtn);

bcolbtn.UniqueName =

"SelectColumnDown";

 

bcolbtn.CommandName =

"SelectDown";

 

bcolbtn.Text =

"Down";

 

bcolbtn.ImageUrl =

"~/images/ButtonDownArrow.png";

 

bcolbtn.ButtonType =

GridButtonColumnType.ImageButton;

 

bcolbtn.ItemStyle.HorizontalAlign =

HorizontalAlign.Center;

 

bcolbtn.HeaderStyle.Width =

Unit.Pixel(30);

 



When the button Type is not set the text is shown and the RadGrid1_ItemCommand event fires passing in the CommandName of SelectUp and SelectDown but when I make the button type ImageButton the event never fires.
0
Pavel
Telerik team
answered on 25 Jul 2011, 02:33 PM
Hi Chris,

I tested the sample attached in my previous post with a different CommandName setting and it still works. Let me know how to alter it in order to replicate the issue.

Best wishes,
Pavel
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Matthew
Top achievements
Rank 1
answered on 25 Jul 2011, 04:22 PM
0
Pavel
Telerik team
answered on 27 Jul 2011, 08:24 AM
Hello Matthew,

As explained previously I cannot reproduce the problem with your directions. You can use the attached sample as a reference point and let me know what I am missing.

Regards,
Pavel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Matthew
Top achievements
Rank 1
answered on 27 Jul 2011, 09:42 AM
Ok, my directions where extremely simple, but I'll take you through it...

1. Delete the page load method from your sample page.

2. Copy and paste the code that I put up in my post over the top: http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-itemcommand-not-firing-for-buttontype-imagebutton.aspx#1558064

3. If you're copy and paste isn't working, just remove the need datasource event handler and just bind the grid to some data on page load (without any "if (!IsPostback)", exactly as per my example). This is to simulate grids that may be bound to different data on a postback, e.g. when you've got two grids and are doing drag and drop.

4. Put a breakpoint on the itemcommand event.

5. Watch it not hit that breakpoint when you click the GridButtonColumns Image button.

6. Change it to a linkbutton and watch it work.
0
Pavel
Telerik team
answered on 28 Jul 2011, 07:36 AM
Hello Matthew,

When binding the Grid with simple data binding (using DataBind() method) it is not correct to do it on every page load, as the data will be persisted in ViewState. Only when you have operations like paging and sorting you need to assign the data source in the specific event, as illustrated in this example. In your scenario the wrong binding leads to an event validation server-side exception when the image button is pressed. This is not related to the execution of the ItemCommand event.

Regards,
Pavel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Rommel
Top achievements
Rank 1
answered on 15 Jan 2013, 04:21 PM
All you need to do is use RadAjaxManager control and set its property EnableAJAX = "false" :)
0
Justin
Top achievements
Rank 1
answered on 08 Jan 2014, 04:47 PM
I have the same problem, any fix for this?  I'm using CommandName="Delete", which works for all buttons except ImageButton.  Don't see why we need to do hacky work arounds for different button types.
0
Shinu
Top achievements
Rank 2
answered on 09 Jan 2014, 06:19 AM
Hi Justin,

Below is a sample code snippet that i tried which works fine at my end, can you please try and see if the issue exists. If this doesn't help please provide your code.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true" AllowPaging="true"
    AllowMultiRowSelection="true" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand">
    <MasterTableView>
        <Columns>
            <telerik:GridButtonColumn ButtonType="ImageButton" Text="Delete" CommandName="Delete"
                UniqueName="GridButtonColumn">
            </telerik:GridButtonColumn>
        </Columns>
    </MasterTableView>  
</telerik:RadGrid>

C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data = new[] {
    new { ID = 1, Name = "Name1"},
    new { ID = 2, Name = "Name2"},
    new { ID = 3, Name = "Name3"},
    new { ID = 4, Name = "Name4"},
    new { ID = 5, Name = "Name5"},
    new { ID = 6, Name = "Name6"},
    new { ID = 7, Name = "Name7"},
    new { ID = 8, Name = "Name8"},
    new { ID = 9, Name = "Name9"}
 };
    RadGrid1.DataSource = data;
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "Delete")
    {
        //Your Code
    }
}

Thanks,
Shinu
0
Shinu
Top achievements
Rank 2
answered on 09 Jan 2014, 06:21 AM
.
0
TechSavvySam
Top achievements
Rank 1
answered on 06 Feb 2015, 01:44 PM
Thanks, that fixed my issue.  I'm creating some new code from scratch and was inadvertently rebinding the grid on every post back.  This keeps the ItemCommand event from ever being called.
0
TechSavvySam
Top achievements
Rank 1
answered on 06 Feb 2015, 01:46 PM
Argh!  This forum puts your reply at the bottom of the page, so you can't tell which message fixed my issue.  It was this one from Pavel:

When binding the Grid with simple data binding (using DataBind() method) it is not correct to do it on every page load, as the data will be persisted in ViewState. Only when you have operations like paging and sorting you need to assign the data source in the specific event, as illustrated in this example. In your scenario the wrong binding leads to an event validation server-side exception when the image button is pressed. This is not related to the execution of the ItemCommand event.
0
Gaetan
Top achievements
Rank 1
answered on 17 Sep 2015, 09:04 AM

Hi Shinu

 

Same issue with very similar code, except radgrid inside radwindow popup...

Does the radwindow and radgridview cope well together??

Thanks,

 

[quote]Shinu said:Hi Justin,

Below is a sample code snippet that i tried which works fine at my end, can you please try and see if the issue exists. If this doesn't help please provide your code.

ASPX:

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true" AllowPaging="true"
    AllowMultiRowSelection="true" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand">
    <MasterTableView>
        <Columns>
            <telerik:GridButtonColumn ButtonType="ImageButton" Text="Delete" CommandName="Delete"
                UniqueName="GridButtonColumn">
            </telerik:GridButtonColumn>
        </Columns>
    </MasterTableView>  
</telerik:RadGrid>

C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data = new[] {
    new { ID = 1, Name = "Name1"},
    new { ID = 2, Name = "Name2"},
    new { ID = 3, Name = "Name3"},
    new { ID = 4, Name = "Name4"},
    new { ID = 5, Name = "Name5"},
    new { ID = 6, Name = "Name6"},
    new { ID = 7, Name = "Name7"},
    new { ID = 8, Name = "Name8"},
    new { ID = 9, Name = "Name9"}
 };
    RadGrid1.DataSource = data;
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "Delete")
    {
        //Your Code
    }
}

Thanks,
Shinu[/quote]
0
Gaetan
Top achievements
Rank 1
answered on 17 Sep 2015, 09:13 AM

actually, it's a Radgridview in a radwindow + a RadAjaxManager to dispatch events....

Does it sound too much??

 

0
Angel Petrov
Telerik team
answered on 22 Sep 2015, 10:49 AM
Hello Gaetan,

You should not experience any problems when combining the three controls. Please share with us the problematic code so we could examine it. One we have a better view over the exact implementation we should be able to provide you with a more precise answer.

Regards,
Angel Petrov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Gaetan
Top achievements
Rank 1
answered on 22 Sep 2015, 11:41 AM

problem disappeared after I removed the radwindowmanager from the page.

 Thanks,

Gaetan

 

0
Rajan
Top achievements
Rank 1
answered on 28 Oct 2015, 12:32 PM

I am facing a weird problem with ItemCommand. I have a radGrid which is part of a User Control. This user control is added as part of another aspx page and ItemCommand is triggered and working fine when a button from GridButtonColumn is clicked. However when this user control is added within another user control, ItemCommand is not triggered at all. This RadGrid is part of RadAjaxPanel. When RadAjaxPanel is removed, ItemCommand is triggered in all scenario. Here is how ASPX looks like

<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="WebBlue">
</telerik:RadAjaxLoadingPanel>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
   
       <telerik:RadGrid ID="radSelect" runat="server" PageSize="20" Width="100%" FooterStyle-BackColor="AliceBlue" AllowFilteringByColumn="True" AllowSorting="True"
            AllowPaging="True" AutoGenerateColumns="False" OnUpdateCommand ="radSelect_UpdateCommand"
           ResolvedRenderMode="Classic" CellSpacing="-1"  OnItemCommand="radSelect_ItemCommand"
        OnNeedDataSource="radSelect_NeedDataSource" CssClass="RadGridMasterDiv"><PagerStyle Mode="NextPrev"  AlwaysVisible="true"></PagerStyle>
        
        <GroupingSettings CaseSensitive="False" />
        <MasterTableView Width="100%" AllowNaturalSort="False" DataKeyNames="EMessageID,EMsgReceiverID" ClientDataKeyNames="EMessageID">
            <HeaderStyle Font-Bold="true" />
            <CommandItemSettings ShowAddNewRecordButton="False" ShowRefreshButton="False" />
            <Columns>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn ReadOnly="true" DataField="SubjectLine" AllowFiltering="true"  UniqueName="Subject" CurrentFilterFunction="Contains" AutoPostBackOnFilter="True" ShowFilterIcon="false">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn ReadOnly="true" DataField="DisplayStatus" UniqueName="Status" CurrentFilterFunction="Contains" AutoPostBackOnFilter="True" ShowFilterIcon="false">
                </telerik:GridBoundColumn>
                <telerik:GridButtonColumn UniqueName="ResendButton" CommandName="Resend">
                </telerik:GridButtonColumn>
            </Columns>           
        </MasterTableView>           
    </telerik:RadGrid>
    <telerik:RadToolTip ID="RadToolTip1" runat="server" OffsetY="3" Position="TopCenter"
                    ShowCallout="false" Height="20px" ShowEvent="fromcode" />
</telerik:RadAjaxPanel>

Can someone guide me on what could be the possible reason for ItemCommand not to work? I am clueless on how to debug this issue.

0
Angel Petrov
Telerik team
answered on 02 Nov 2015, 06:40 AM
Hi,

Please check in the browser console whether a JavaScript error is raised. Additionally please verify that the container in which the control is loaded is not ajaxifyed by a RadAjaxManager.

Regards,
Angel Petrov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Matthew
Top achievements
Rank 1
Mike
Top achievements
Rank 2
Ryan
Top achievements
Rank 1
Pavel
Telerik team
Chris
Top achievements
Rank 1
Rommel
Top achievements
Rank 1
Justin
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
TechSavvySam
Top achievements
Rank 1
Gaetan
Top achievements
Rank 1
Angel Petrov
Telerik team
Rajan
Top achievements
Rank 1
Share this question
or