Reputation: 139
Basically I have a masterpage defining the basic layout of the website. What I am trying to do is, in the child page change the contents of a div. I know I can use this:
//((HtmlGenericControl)this.Page.Master.Master.FindControl("friends")).InnerHtml = "";
But I can't put tags in this for example if I wanted to change the div and insert an unordered list.
How can I do this and if you could post an example I'd appreciate it. Cheers.
Upvotes: 0
Views: 621
Reputation: 7438
You can expose div as a server side control like PlaceHolder and Add control to it by div.Controls.Add(control);
at serverside code of child forms.
Upvotes: 1
Reputation: 121
HtmlGenericControl div = (HtmlGenericControl)Page.FindControl("<<div id>>");
HtmlGenericControl ul = HtmlGenericControl("ul")
HtmlGenericControl liToAdd = null;
HtmlGenericControl linkToAdd = null;
for (int i = 0; i < 10; i++)
{
liToAdd = new HtmlGenericControl("li");
linkToAdd = new HtmlGenericControl("a");
linkToAdd.InnerText = "demo";
linkToAdd.Attributes.Add("href", "");
liToAdd.Controls.Add(linkToAdd);
ul.Controls.Add(liToAdd);
}
div.Controls.Add(ul);
Upvotes: 0