How to add Iframe to a Rad Panel Item Dynamically?

2 posts, 0 answers
  1. Santhosh
    Santhosh avatar
    1 posts
    Member since:
    Nov 2011

    Posted 29 Nov 2011 Link to this post

    Hi Team, 
     My Requirement is to open PDF File in Rad Panel Item. When I do it from design mode it is working fine, but I am unable to add Iframe from code behind.
    When I used Iframe from design mode : 
                     <telerik:RadPanelBar ID="radSample" runat="server">
                               <iframe id="sample123" runat="server" src="~/UpLoadedImages/abc.pdf"></iframe>
      when I used like this it is working fine and pdf is opening in Iframe but now i need to add rad panel items dynamically,
    but as per my requirement i may have add number of rad panel items  so for that,     
    count = no. of items;
    foreach(int i=0 ; i < count; i++)
                             RadPanelItem myItem= new RadPanelItem();
     System.Web.UI.HtmlControls.HtmlGenericControl Iframe1 = new System.Web.UI.HtmlControls.HtmlGenericControl();
                            Iframe1.Attributes["src"] = "~/UpLoadedImages/abc.pdf";
    Now IFrame is adding like a span tag and not working as expected.

    Can you help me how to add Iframe control to Rad Panel Item dynamically....

     Thanks in Advance..

  2. Kate
    Kate avatar
    1898 posts

    Posted 30 Nov 2011 Link to this post

    Hi Santhosh,

    Here is an example of how you can add an iframe in a ContentTemplate of a RadPanelBar control using code behind:
    public partial class PanelBar_PanelBar1 : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            CustomContentTemplate template = new CustomContentTemplate();
            foreach (RadPanelItem item in RadPanelBar1.Items)
                item.ContentTemplate = new CustomContentTemplate();
        class CustomContentTemplate : ITemplate
            public void InstantiateIn(Control container)
                var Iframe1 = new HtmlGenericControl("IFRAME");
                Iframe1.Attributes["height"] = "300px";
                Iframe1.Attributes["width"] = "300px";
                Label label1 = new Label();
                label1.Text = "neeeew";
                label1.Font.Bold = true;

    <telerik:RadPanelBar ID="RadPanelBar1" runat="server">
              <telerik:RadPanelItem runat="server" Text="Root RadPanelItem1" Value="A">
              <telerik:RadPanelItem runat="server" Text="Root RadPanelItem2" Value="B">
              <telerik:RadPanelItem runat="server" Text="Root RadPanelItem3" Value="C">

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top