Add Elements in Radio Button Runtime

2 posts, 0 answers
  1. Krishna
    Krishna avatar
    1 posts
    Member since:
    Jul 2012

    Posted 01 Aug 2012 Link to this post

    How can we change image source in Readion Button Content Template at run time depending on specific condition?



    <telerik:RadButton runat="server" ID="RadButton1" Width="90"
               Height="90" CssClass="tasks" Skin="Default">
               <ContentTemplate>
                   <img alt="cog" src="Img/cog.png" />
                   <span class="btnText">Tasks</span>
               </ContentTemplate>
           </telerik:RadButton>
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Aug 2012 Link to this post

    Hi Krishna,

    Here is the sample code that I tried to change the image source dynamically.

    ASPX:
    <telerik:RadButton runat="server" ID="RadButton1" Width="90" Height="90" CssClass="tasks" Skin="Default">
      <ContentTemplate>
        <img alt="cog" src="../Images/image1.jpg" id="image" runat="server" />
        <span class="btnText">Tasks</span>
      </ContentTemplate>
    </telerik:RadButton>

    C#:
    if(Your Condition)
      {
        HtmlImage img =(HtmlImage) RadButton1.FindControl("image");
        img.Src = "../Images/image2.jpg";
      }
    else
      {
        HtmlImage img =(HtmlImage) RadButton1.FindControl("image");
        img.Src = "../Images/image3.jpg";
      }

    Hope this helps.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top