Microsoft has provided many helper funtions in c#  by which we can easily load webpage content dyncamilly by code.

Load Webpages dynamically by c# code

Microsoft has provided many helper funtions in c#  by which we can easily load webpage content dyncamilly by code.

Here we will be trying with C# code. The code for other languages in .net will be similar.

We can use IFrame in our web development applications developed in asp.net, VB.net, C#.net equally same.

1.

Using IFrame control in the Markup of the page

<iframe runat=”server” id=”iframe1″ scrolling=”auto”></iframe>

This defines an IFrame which can be controlled by asp.net code behind.

2.

Using IFrame control in the Markup of the page along with src

<iframe runat=”server” id=”iframe1″ scrolling=”auto” src=”http://www.google.com”></iframe>

This will load the IFrame which loads the webpage as defined in src=”/Portals/0/…google.com” tag.

3.

What type of control is this IFrame ?

protected System.Web.UI.HtmlControls.HtmlGenericControl frame1;

This is a HTMLGenericControl which is defined within HTMLControls namespace.

4.

How to set the IFrame src property in C# code ?

frame1.Attributes[“src”] = “http://www.ommrudraksha.com” ;

This way we can set the src property of the IFrame control by code.

5. 

How to set the Height and width of the IFrame Control ?

frame1.Attributes[“src”] = src;
frame1.Attributes[“width”] = “100%”;
frame1.Attributes[“height”] = “600px”;

Here this way we can dynamically set the source and also the height and width property by code.

We can use 100% for giving it by percentage or by 600px to give exact size.

6.

What all properties available for IFrame ?

There are many properties available for the IFrame control. See the below image for all properties list for IFrame control.

Leave a Comment