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

How to add Iframe to a Rad Panel Item Dynamically?

1 Answer 172 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Santhosh
Top achievements
Rank 1
Santhosh asked on 29 Nov 2011, 07:08 AM
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">
                      <Items>
                        <telerik:RadPanelItem>
                          <ContentTemplate>
                           <iframe id="sample123" runat="server" src="~/UpLoadedImages/abc.pdf"></iframe>
                          </ContentTemplate>
                        </telerik:RadPanelItem>
                      </Items>
                    </telerik:RadPanelBar>
  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";
                        myItem.Controls.Add(Iframe1);
radPnlBar1.Items.Add(myItem);
}
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..

 Santhosh.G,

1 Answer, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 30 Nov 2011, 05:18 PM
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();
            template.InstantiateIn(item);
        }
    }
 
    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;
 
            container.Controls.Add(label1);
            container.Controls.Add(Iframe1);
        }
    }
}

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

Greetings,
Kate
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
Tags
PanelBar
Asked by
Santhosh
Top achievements
Rank 1
Answers by
Kate
Telerik team
Share this question
or