Set button checked in code

3 posts, 1 answers
  1. John Davis
    John Davis avatar
    119 posts
    Member since:
    Apr 2007

    Posted 08 May 2008 Link to this post

    How do you set a two-state button as "checked" in program code?  For example, in the following Telerik example how do you set as checked the button having ImageUrl="~/Images/J.gif" ?

    <telerik:RadToolBar ID="RadToolBar1" runat="server" Skin="Hay" >
     
    <Items>
       
    <telerik:RadToolBarButton
         
    runat="server"
         
    ImageUrl="~/Images/bold.gif"
         
    AllowSelfUnCheck="True"
         
    CheckOnClick="True" />
       
    <telerik:RadToolBarButton
         
    runat="server"
         
    ImageUrl="~/Images/Italic.gif"
         
    AllowSelfUnCheck="True"
         
    CheckOnClick="True" />
       
    <telerik:RadToolBarButton
         
    runat="server"
         
    ImageUrl="~/Images/underline.gif"
         
    AllowSelfUnCheck="True"
         
    CheckOnClick="True" />
       
    <telerik:RadToolBarButton
         
    runat="server"
         
    Enabled="False"
         
    Text="|" />
       
    <telerik:RadToolBarButton
         
    runat="server"
         
    Checked="True"
         
    CheckOnClick="True"
         
    Group="Justify"
         
    ImageUrl="~/Images/LJ.gif" />
       
    <telerik:RadToolBarButton
         
    runat="server"
         
    CheckOnClick="True"
         
    Group="Justify"
         
    ImageUrl="~/Images/J.gif" />
       
    <telerik:RadToolBarButton
         
    runat="server"
         
    CheckOnClick="True"
         
    ImageUrl="~/Images/RJ.gif" />
     
    </Items>
    </
    telerik:RadToolBar>
  2. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 09 May 2008 Link to this post

    Hello John Davis,

    You need to first find the button you want for example by using FindItemByValue method. Then you need to cast it to RadToolBarButton class and set its Checked property to true.

        protected void Page_Load(object sender, EventArgs e) 
        { 
            RadToolBarButton btn = (RadToolBarButton)RadToolBar1.FindItemByValue("J"); 
            btn.Checked = true
        } 

    I have set Value="J" for that particular item.

    I hope this helps.

    Kind regards,
    Veskoni
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. John Davis
    John Davis avatar
    119 posts
    Member since:
    Apr 2007

    Posted 09 May 2008 Link to this post

    Veskoni
    It works perfectly. Thank you.
    john
Back to Top