Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using iFrames In ASP.NET

Tags:

I have an asp.net website with a master-page, can I use the iframe so my .aspx pages will load inside the iframes. (Meaning it wont load the master-page)

Kinda like my iframe will be the contentplaceholder or maybe the contentplaceholder will be inside it?

Any Ideas?

like image 241
Or Betzalel Avatar asked Feb 16 '11 10:02

Or Betzalel


People also ask

What is the use of iframe in asp net?

The <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document.

Are IFrames still used 2021?

<iframe> is not an obsolete or deprecated tag. It's still widelly used in the web, mostly for media purposes.

How do I use iframe in Webforms?

You can put an iframe in any HTML page, so you could put one inside a contentplaceholder in a webform that has a Masterpage and it will appear with whatever URL you load into it (via Javascript, or C# if you turn your iframe into a server-side control ( runat='server' ) on the final HTML page that your webform produces ...

Should I still use IFrames?

Google Says Do Not Use iFrames In fact, even Google says, don't do it – straight from its developer site: “We recommend that you avoid the use of iFrames to display content.”


2 Answers

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"); } 
like image 141
santosh singh Avatar answered Oct 05 '22 15:10

santosh singh


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 />")); 
like image 42
owen gerig Avatar answered Oct 05 '22 15:10

owen gerig