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

PushButton not firing ItemCommand event

2 Answers 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Samwise
Top achievements
Rank 1
Samwise asked on 17 Feb 2009, 02:05 PM
Hello,

I am using the (latest?) version 2008.3.1125.35 of the Telerik RadControls for ASP.NET Ajax.
In this small example below, I can not make the pushbutton fire the ItemCommand event. With the ImageButton, everything is fine.
It is not a blocking thing but I would rather use a button because I have a css class ready for it.
Can someone please tell me if it is a bug or am I doing something wrong?

Thank you,

Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication4._Default" %> 
 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server">  
    <title></title>  
</head> 
<body> 
    <form id="form1" runat="server">  
    <asp:ScriptManager ID="ScriptManager1" runat="server">  
    </asp:ScriptManager> 
    <div> 
      
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"   
            AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"   
            GridLines="None" onitemcommand="RadGrid1_ItemCommand"   
            onitemdatabound="RadGrid1_ItemDataBound">  
<HeaderContextMenu> 
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
</HeaderContextMenu> 
 
<MasterTableView datakeynames="CategoryID" datasourceid="SqlDataSource1">  
<RowIndicatorColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</RowIndicatorColumn> 
 
<ExpandCollapseColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</ExpandCollapseColumn> 
    <Columns> 
        <telerik:GridBoundColumn DataField="CategoryID" DataType="System.Int32"   
            HeaderText="CategoryID" ReadOnly="True" SortExpression="CategoryID"   
            UniqueName="CategoryID">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="CategoryName" HeaderText="CategoryName"   
            SortExpression="CategoryName" UniqueName="CategoryName">  
        </telerik:GridBoundColumn> 
        <telerik:GridButtonColumn CommandName="DeleteP" UniqueName="DeleteP" Text="Delete" ButtonType="PushButton">  
        </telerik:GridButtonColumn> 
        <telerik:GridButtonColumn CommandName="DeleteL" UniqueName="DeleteL" Text="Delete" ButtonType="LinkButton">  
        </telerik:GridButtonColumn> 
    </Columns> 
</MasterTableView> 
 
<FilterMenu> 
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
</FilterMenu> 
        </telerik:RadGrid> 
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"   
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"   
            SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]">  
        </asp:SqlDataSource> 
      
    </div> 
    <telerik:RadAjaxManager runat="server">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    </form> 
</body> 
</html> 
 

Default.aspx.cs:
using System.Web.UI;  
using System.Web.UI.WebControls;  
using Telerik.Web.UI;  
 
namespace WebApplication4  
{  
    public partial class _Default : Page  
    {  
        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
        {  
            string cmdName = e.CommandName;  
            string cmdArg = e.CommandArgument.ToString();  
        }  
 
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
        {  
            if (e.Item is GridDataItem)  
            {  
                var dataBoundItem = e.Item as GridDataItem;  
 
                var btnP = dataBoundItem["DeleteP"].Controls[0] as Button;  
                btnP.OnClientClick = "return confirm('ok " + dataBoundItem["CategoryName"].Text + "?');";  
                btnP.CommandArgument = dataBoundItem["CategoryID"].Text;  
 
                var btnL = dataBoundItem["DeleteL"].Controls[0] as LinkButton;  
                btnL.OnClientClick = btnP.OnClientClick;  
                btnL.CommandArgument = btnP.CommandArgument;  
            }  
        }  
    }  

2 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetoslav
Telerik team
answered on 18 Feb 2009, 02:58 PM
Hello Samwise,

If you examine the html for the button generated by RadGrid you will get:

<input type="button" onclick="return confirm('ok Beverages?');__doPostBack('RadGrid1$ctl00$ctl04$ctl00','')" value="Delete" name="RadGrid1$ctl00$ctl04$ctl00"/> 
So, you are alway returning before the call to the postback method, never giving the button the opportunity to post back the page.

Therefore, you should change your client script for the button's ClientClick event to:

"if(!confirm('ok " + dataBoundItem["CategoryName"].Text + "?')){return false;}"

Hope this helps.

Regards,
Tsvetoslav
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
Samwise
Top achievements
Rank 1
answered on 18 Feb 2009, 03:44 PM
Yes, it works now! Thank you!
Tags
Grid
Asked by
Samwise
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Samwise
Top achievements
Rank 1
Share this question
or