Tuesday, May 1, 2012

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);

Source: https://www.nilebits.com/blog/2011/04/how-to-programmatically-create-iframe-in-asp-net/

No comments:

Post a Comment