I have a server control that I have written, which generally works fine. However when I add in the highlighted line, it adds in not one but two <br /> elements, which is not what I am after.
mounting=new DropDownLabel();
mounting.ID="mountTypeList";
mounting.Attributes.Add("class", "mounting");
mounting.Values=Configuration.MountTypes.GetConfiguration().Options;
mounting.Enabled=Utilities.UserType == UserType.Admin;
mounting.Value=value.Reference;
td1.Controls.Add(mounting);
**td1.Controls.Add(new HtmlGenericControl("br"));**
var span=new HtmlGenericControl("span");
span.Attributes.Add("class", "mountDescription");
span.ID="mountDescription";
td1.Controls.Add(span);
Any thoughts on what I am doing wrong?
ETA:
I have resolved the situation by adding the br using jquery, which I am using there anyway. But the behaviour I saw is surely wrong. If I add an element, it should add that element, not twice that element.
HtmlGenericControlwill generate the with the opening and closing tags<br>and</br>instead you could use
new LiteralControl("<br/>")which should do what you desire.EDIT
To get around this you will need your own implementation of the
HtmlGenericControland extend it for such cases which don’t have opening and closing tags associated.Found Here