Hi,
I have a usercontrol defined as:
<P>
<a id="sectionName" runat="server"></a>
<asp:PlaceHolder id="detailsBody" runat="server">
</asp:PlaceHolder>
<br>
<asp:HyperLink id="hrefTop" runat="server" NavigateUrl="#top">Top
</asp:HyperLink></P>
In the cs code I have added some public properties and a public method,
which set some of the control properties itself:
public string AnchorName
{
get {return this.sectionName.Name;}
set {this.sectionName.Name = value;}
}
//add a line in the placeholder
public void AddDetailsLine(string text)
{
HtmlGenericControl line = new HtmlGenericControl("div");
line.InnerText = text;
this.Controls.Add(line);
}
My main page is this:
<body MS_POSITIONING="FlowLayout">
<form id="Main" runat="server">
<a id="topAnchor" name="top" runat="server"></a>
<P><asp:placeholder id="Addresses" runat="server"></asp:placeholder></P>
</form>
</body>
On page load I want to add dynamically in the placeholder some of my
usercontrols. So I have:
private void Page_Load(object sender, System.EventArgs e)
{
//load the control
UC firstSec = (UC)Page.LoadControl("UC.ascx");
//setup the control
firstSec.AnchorName = "Chicago";
firstSec.AddDetailsLine("Street address");
firstSec.AddDetailsLine("City address");
firstSec.AddDetailsLine("State address");
//add to page
this.Addresses.Controls.Add(firstSec);
}
The problem is that this renders to:
<form name="Main" method="post" action="Default.aspx" id="Main">
<a id="topAnchor" name="top"></a>
<P>
<a id="_ctl2_sectionName" name="Chicago"></a>
<br>
<a id="_ctl2_hrefTop" href="#top">List</a></P>
<div>Street address</div><div>City address</div><div>State address</div>
</P>
</form>
As you can see it puts the content of the placeholder after the <a> tag,
which is not the way the control is defined.
Can someone reproduce it, or show me the mistake in my code, or possible
workaround.
Thanks
Sunny
P.S. Thanks again for reading so long post :)