I have a RadGrid on my page, with a button in the CommandItemTemplate. I want to execute a client function to determine if I need to postback to do some work to do something else on the client side. When I do this, the button no longer causes a postback. It will not postback even if I simplet do OnClientClick="return true;". Is there a way to work around this. Here is some sample code.
ASPX
Here is the c# code behind:
Thanks,
Doug
ASPX
| <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="GridTest._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>Untitled Page</title> |
| <script language="javascript" type="text/javascript"> |
| function onBtnClick() |
| { |
| return true; |
| } |
| </script> |
| </head> |
| <body> |
| <form id="form1" runat="server"> |
| <telerik:RadScriptManager runat="server"> |
| </telerik:RadScriptManager> |
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="RadGrid1"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="lbl" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| <div> |
| <asp:Label ID="lbl" runat="server"></asp:Label> |
| <telerik:RadGrid ID="RadGrid1" Skin="WebBlue" Width="500" runat="server" GridLines="None" |
| onitemcommand="RadGrid1_ItemCommand"> |
| <MasterTableView CommandItemDisplay="Top"> |
| <CommandItemTemplate> |
| <asp:Button ID="btnCmd" CommandName="ShowTime" OnClientClick="return onBtnClick();" runat="server" Text="Do Something" /> |
| </CommandItemTemplate> |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </ExpandCollapseColumn> |
| </MasterTableView> |
| </telerik:RadGrid> |
| </div> |
| </form> |
| </body> |
| </html> |
Here is the c# code behind:
| using System; |
| using System.Collections; |
| using System.Collections.Generic; |
| using System.Configuration; |
| using System.Data; |
| using System.Linq; |
| using System.Web; |
| using System.Web.Security; |
| using System.Web.UI; |
| using System.Web.UI.HtmlControls; |
| using System.Web.UI.WebControls; |
| using System.Web.UI.WebControls.WebParts; |
| using System.Xml.Linq; |
| namespace GridTest |
| { |
| public partial class _Default : System.Web.UI.Page |
| { |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (!IsPostBack) |
| { |
| List<Sample> sampleList = new List<Sample>(); |
| for (int x = 0; x < 15; x++) |
| { |
| Sample s = new Sample(); |
| s.Name = String.Format("Name {0}", x); |
| s.Description = String.Format("Description for item {0}", x); |
| sampleList.Add(s); |
| } |
| RadGrid1.DataSource = sampleList; |
| RadGrid1.DataBind(); |
| } |
| } |
| protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) |
| { |
| if (e.CommandName == "ShowTime") |
| { |
| lbl.Text = String.Format("Processed at {0}.", DateTime.Now.ToLongTimeString()); |
| } |
| } |
| } |
| public class Sample |
| { |
| public string Name { get; set; } |
| public string Description { get; set; } |
| } |
| } |
Thanks,
Doug