Using iFrames In ASP.NET Using iFrames In ASP.NET asp.net asp.net

Using iFrames In ASP.NET


try this

<iframe name="myIframe" id="myIframe" width="400px" height="400px" runat="server"></iframe>

Expose this iframe in the master page's codebehind:

public HtmlControl iframe{get{return this.myIframe;}}

Add the MasterType directive for the content page to strongly typed Master Page.

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits=_Default" Title="Untitled Page" %><%@ MasterType VirtualPath="~/MasterPage.master" %>

In code behind

protected void Page_Load(object sender, EventArgs e){this.Master.iframe.Attributes.Add("src", "some.aspx");}


Another option is to use placeholders.

Html:

<body>   <div id="root">      <asp:PlaceHolder ID="iframeDiv" runat="server"/>   </div></body>

C#:

iframeDiv.Controls.Add(new LiteralControl("<iframe src=\"" + whatever.com + "\"></iframe><br />"));


How about:

<asp:HtmlIframe ID="yourIframe" runat="server" />

Is supported since .Net Framework 4.5

If you have Problems using this control, you might take a look here.