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

How do i add a class to rad button dynamically code behind

1 Answer 1085 Views
Button
This is a migrated thread and some comments may be shown as answers.
Philip
Top achievements
Rank 1
Philip asked on 05 Jun 2016, 04:13 PM

I am using the following mark up for a toolbar at the top of my screen but their is a diabled css class that i can add and an active to make them stand out my question is how do i in code behind add a style to the button cssclass tag.

 

<telerik:RadButton ID="rbPersonalDetails" runat="server" CssClass="btn btn-info" Text="Property Details">
 
                <ContentTemplate>
                    <i class="fa fa-user" style="color: #5bc0de;"></i>Personal Details
                </ContentTemplate>
 
            </telerik:RadButton>
            <telerik:RadButton ID="rbPropertyDetails" runat="server" CssClass="btn btn-info" Text="Property Details">
 
                <ContentTemplate>
                    <i class="fa fa-home" style="color: #5bc0de;"></i>Property Details
                </ContentTemplate>
 
            </telerik:RadButton>
            <telerik:RadButton ID="rbVechicleDetails" runat="server" CssClass="btn btn-info" Text="Vechicle Details">
 
                <ContentTemplate>
                    <i class="fa fa-car" style="color: #5bc0de;"></i>Vechicle Details
                </ContentTemplate>
 
            </telerik:RadButton>
 
            <telerik:RadButton ID="rbincomee" runat="server" CssClass="btn btn-info">
 
                <ContentTemplate>
                    <i class="fa fa-gbp" style="color: #5bc0de;"></i>Income & Expenditures
                </ContentTemplate>
 
            </telerik:RadButton>
 
 
 
            <telerik:RadButton ID="rbPensions" runat="server" CssClass="btn btn-info">
 
                <ContentTemplate>
                    <i class="fa fa-bank" style="color: #5bc0de;"></i>Pensions
                </ContentTemplate>
 
            </telerik:RadButton>
 
            <telerik:RadButton ID="rbMeetings" runat="server" CssClass="btn btn-info">
 
                <ContentTemplate>
                    <i class="fa fa-calendar" style="color: #5bc0de;"></i>Meetings
                </ContentTemplate>
 
            </telerik:RadButton>
 
            <telerik:RadButton ID="rbOtherAssets" runat="server" CssClass="btn btn-info" >
 
                <ContentTemplate>
                    <i class="fa fa-share" style="color: #5bc0de;"></i>Other Assets
                </ContentTemplate>
 
            </telerik:RadButton>

1 Answer, 1 is accepted

Sort by
0
Misho
Telerik team
answered on 08 Jun 2016, 08:35 AM
Hello,

Here is the sample that is showing how to add custom css class to RadButton in the code behind:

<form id="form1" runat="server">
 
       <asp:ScriptManager runat="server"></asp:ScriptManager>
       <asp:Button runat="server" Text="Disable RadButton" OnClick="ButtonClicked"/>
       <telerik:RadButton ID="rbPersonalDetails" runat="server" CssClass="btn btn-info" Text="Property Details">
           <ContentTemplate>
               <i class="fa fa-user" style="color: #5bc0de;"></i>Personal Details
           </ContentTemplate>
       </telerik:RadButton>
       <telerik:RadButton ID="RadButton1" runat="server" CssClass="btn btn-info" Enabled="false" Text="Property Details">
           <ContentTemplate>
               <i class="fa fa-user" style="color: #5bc0de;"></i>Personal Details
           </ContentTemplate>
       </telerik:RadButton>
       <telerik:RadButton ID="RadButton2" runat="server" CssClass="btn btn-info"  Text="Property Details">
           <ContentTemplate>
               <i class="fa fa-user" style="color: #5bc0de;"></i>Personal Details
           </ContentTemplate>
       </telerik:RadButton>
       <div>
       </div>
 
 
       <script runat="server">
           protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           Response.Write(RadButton2.CssClass);
       }
   }
 
   protected void ButtonClicked(object sender, EventArgs e)
   {
       rbPersonalDetails.Enabled = false;
       RadButton2.CssClass += " disabled";
       Response.Write(RadButton2.CssClass);
   }
 
       </script>
   </form>
 In addition you can review the following help article:

http://docs.telerik.com/devtools/aspnet-ajax/controls/button/server-side-programming/properties-and-events#radbuttontogglestate-specific-features-properties

I hope that helps.

Regards,
Misho
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Button
Asked by
Philip
Top achievements
Rank 1
Answers by
Misho
Telerik team
Share this question
or