Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6606331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:23:04+00:00 2026-05-25T19:23:04+00:00

I have a server control that I have written, which generally works fine. However

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:23:05+00:00Added an answer on May 25, 2026 at 7:23 pm

    HtmlGenericControl will 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 HtmlGenericControl and extend it for such cases which don’t have opening and closing tags associated.

    public class HtmlGenericSelfClosing : HtmlGenericControl
    {
        public HtmlGenericSelfClosing()
            : base()
        {
        }
    
        public HtmlGenericSelfClosing(string tag)
            : base(tag)
        {
        }
    
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write(HtmlTextWriter.TagLeftChar + this.TagName);
            Attributes.Render(writer);
            writer.Write(HtmlTextWriter.SelfClosingTagEnd);
        }
    
        public override ControlCollection Controls
        {
            get { throw new Exception("Self-closing tag cannot have child controls"); }
        }
    
        public override string InnerHtml
        {
            get { return String.Empty; }
            set { throw new Exception("Self-closing tag cannot have inner content"); }
        }
    
        public override string InnerText
        {
            get { return String.Empty; }
            set { throw new Exception("Self-closing tag cannot have inner content"); }
        }
    }
    

    Found Here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using ASP.Net, I have a server control for which i would like to add
Is there a way that I can have a server control MyControl<T> so that
I have a server that I have no control over, it's JSON based and
I have a master page that contains an ASP.NET server side Menu control (System.Web.UI.WebControls.Menu)
I want to read UTF-8 strings from a server that I have control of,
I have extended a server control (not a user control) and put the code
I have an ASP.NET server control which relies on JQuery for certain functionality. I've
I have written a user control that captures some user input and has a
I have written a Custom Control that contains the following: [assembly: System.Web.UI.WebResource(InSysControls.AssignmentLists.AssignmentLists.js, text/javascript)] namespace
I've written a simple ascx user control called myLight that I programtically add several

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.