Wednesday, June 23, 2010

Want to create an html link <a href=""></a> and Iframe using C# - dynamically

// Create a new HtmlAnchor control.
HtmlAnchor NewAnchorControl = new HtmlAnchor();

// Set the properties of the new HtmlAnchor control.
NewAnchorControl.Name = "NewAnchorControl";
NewAnchorControl.HRef = "http://www.microsoft.com";
NewAnchorControl.Target = "_blank";
NewAnchorControl.InnerHtml = "Microsoft Home";

// Add the new HtmlAnchor control to the Controls collection of the
// PlaceHolder control.
ControlContainer.Controls.Add(NewAnchorControl)

//Iframe
HtmlGenericControl frame1 = new HtmlGenericControl("iFrame");
frame1.Attributes.Add("runat", "server");
frame1.Attributes.Add("width", "100px");
frame1.Attributes.Add("height", "100px");
frame1.TagName = "iframe";
frame1.Attributes.Add("src", "http://www.microsoft.com");

ControlContainer.Controls.Add(frame1)

No comments:

Post a Comment