Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. HtmlGenericControl

HtmlGenericControl

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jamauss
    wrote on last edited by
    #1

    Anybody know how to make the HtmlGenericControl output self-closing tags like instead of ? Should I set the InnerHtml or InnerText property to null or something like that?

    M 1 Reply Last reply
    0
    • J jamauss

      Anybody know how to make the HtmlGenericControl output self-closing tags like instead of ? Should I set the InnerHtml or InnerText property to null or something like that?

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, You can use the LiteralControl[^] instead.

      J 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, You can use the LiteralControl[^] instead.

        J Offline
        J Offline
        jamauss
        wrote on last edited by
        #3

        Actually, I'd rather use HtmlGenericControl so I can programatically add element attributes and have to concatenate strings together... Can I achieve this with HtmlGenericControl by overriding the render method or something?

        J M 2 Replies Last reply
        0
        • J jamauss

          Actually, I'd rather use HtmlGenericControl so I can programatically add element attributes and have to concatenate strings together... Can I achieve this with HtmlGenericControl by overriding the render method or something?

          J Offline
          J Offline
          jamauss
          wrote on last edited by
          #4

          and "NOT" have to concatenate strings together, I mean.

          1 Reply Last reply
          0
          • J jamauss

            Actually, I'd rather use HtmlGenericControl so I can programatically add element attributes and have to concatenate strings together... Can I achieve this with HtmlGenericControl by overriding the render method or something?

            M Offline
            M Offline
            minhpc_bk
            wrote on last edited by
            #5

            Hi there, You can easily develop your own HtmlGenericControl by superclassing the HtmlGenericControl class in the .Net framework, the sample code looks something like:

            public class CustomHtmlGenericControl : System.Web.UI.HtmlControls.HtmlGenericControl
            {
            public CustomHtmlGenericControl(string tagName):base(tagName)
            {
            }

            public CustomHtmlGenericControl():base()
            {
            }
                                   
            protected override void Render(System.Web.UI.HtmlTextWriter writer)
            {
            	writer.WriteBeginTag(this.TagName);
            	                   
            	this.RenderAttributes(writer);
                                 
            	this.RenderChildren(writer);
                                  
            	writer.Write("/>");
            }
            

            }

            In addition, you can also override the Render method in the way that you first get the rendered html markup as normal, then simply replace the text ></TagName> with the />, and finally write out the result to the writer.

            J 1 Reply Last reply
            0
            • M minhpc_bk

              Hi there, You can easily develop your own HtmlGenericControl by superclassing the HtmlGenericControl class in the .Net framework, the sample code looks something like:

              public class CustomHtmlGenericControl : System.Web.UI.HtmlControls.HtmlGenericControl
              {
              public CustomHtmlGenericControl(string tagName):base(tagName)
              {
              }

              public CustomHtmlGenericControl():base()
              {
              }
                                     
              protected override void Render(System.Web.UI.HtmlTextWriter writer)
              {
              	writer.WriteBeginTag(this.TagName);
              	                   
              	this.RenderAttributes(writer);
                                   
              	this.RenderChildren(writer);
                                    
              	writer.Write("/>");
              }
              

              }

              In addition, you can also override the Render method in the way that you first get the rendered html markup as normal, then simply replace the text ></TagName> with the />, and finally write out the result to the writer.

              J Offline
              J Offline
              jamauss
              wrote on last edited by
              #6

              Hey, thanks for that...works great.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups