How to programmatically create iFrame in ASP.NET

How to programmatically create iFrame in ASP.NET

Sometimes we may need to create iFrames and use it within GridView or Repeater, and we want to pass some values to it.
This example will show you how to create iFrame Programmatically and add it to a PlaceHolder.

HtmlGenericControl myFrame = new HtmlGenericControl();

myFrame.TagName = "IFRAME";
myFrame.Attributes["src"] = "MyPagePath";
myFrame.Attributes["id"] = "myFrame1";
myFrame.Attributes["name"] = "myFrame1";
myFrame.Attributes["width"] = "500";
myFrame.Attributes["height"] = "500";
myFrame.Attributes["class"] = "frames";

myPlaceHolder.Controls.Add(myFrame);

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *