RadButton Toggle in Editmode RadGrid

5 posts, 2 answers
  1. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 20 Dec 2010 Link to this post

    Hi,
    I have the following in a GridTemplateColumn
    <telerik:RadButton ID="rbTest" runat="server" ButtonType="ToggleButton" Style="padding-left: 25px"
                            ToggleType="CheckBox" AutoPostBack="false" Checked='<%# Test(Eval("Test")) %>'>
                            <ToggleStates>
                                <telerik:RadButtonToggleState PrimaryIconCssClass="rbOk" />
                                <telerik:RadButtonToggleState PrimaryIconCssClass="rbCancel" />
                            </ToggleStates>
                        </telerik:RadButton>
    On the ItemDataBound I am trying to add the OnClientClicked Event, I've also tried the OnClientCheckChanged. I find the control in Editemode and try the below

    rbTest.Attributes.Add(

     

    "OnClientCheckedChanged", "return show('0','0')");

    It just doesn't seem to be firing.

    Any ideas?

    Thanks

     

  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Dec 2010 Link to this post

    Hello Karl,

    The following code snippet shows how to attach the client event "OnClientCheckedChanged" from server side.

    C#:
    GridEditFormItem editform = (GridEditFormItem)e.Item;
    RadButton chk = (RadButton)editform.FindControl("rbTest");
    chk.OnClientCheckedChanged = "OnClientCheckedChanged";


    Regards,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 21 Dec 2010 Link to this post

    Thanks Shinu, that works, but how do I attach the following

    "return show('"

     

     

    + var1 + "','" + var2 + "')"

    These variables are from the grid the index of the row and the datakeyvalue. I need to passs them to the show function.

    Thanks again

     

  5. Answer
    Pero
    Admin
    Pero avatar
    1156 posts

    Posted 21 Dec 2010 Link to this post

    Hi Karl,

    The easiest way would be to provide an anonymous function for the OnClientCheckedChanged property, and call your method with the parameters. Here is an example:

    <%@ Page Language="C#" AutoEventWireup="true" %>
     
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                RadButton1.OnClientCheckedChanged = "function(button, args) { Show('Alert text from the server!'); }";
            }
     
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <script type="text/javascript">
            function Show(text)
            {
                alert(text);
            }
        </script>
        <div>
            <telerik:RadButton ID="RadButton1" runat="server" Text="Anonymous Confirm function"
                ToggleType="CheckBox" AutoPostBack="false">
            </telerik:RadButton>
        </div>
        </form>
    </body>
    </html>


    Greetings,
    Pero
    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.
  6. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 21 Dec 2010 Link to this post

    Thanks, that worked
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017