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. HtmlTextWriter Formatting Issues

HtmlTextWriter Formatting Issues

Scheduled Pinned Locked Moved ASP.NET
help
2 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.
  • R Offline
    R Offline
    Randal Vance Cunanan
    wrote on last edited by
    #1

    Need help on the format of the produced output of the HtmlWriter class. I need to make properly indent the tags in the final rendered output. Sample:

    string[] Names = new string[]
    {
    "Johnny",
    "Mindy",
    "Jossy",
    "Kreuger",
    "Marco"
    };

            HtmlTextWriter writer = new HtmlTextWriter(new StringWriter());
            writer.RenderBeginTag(HtmlTextWriterTag.Ul);
            foreach (string name in Names)
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Li);
                writer.Write(name);
                writer.RenderEndTag();
                writer.WriteLine();
            }
            writer.RenderEndTag();
    

    The produced output is this:

    <ul>
        <li>Johnny</li>
        <li>Mindy</li>
        <li>Jossy</li>
        <li>Kreuger</li>
        <li>Marco</li>
    </ul>

    The closing ul tag is not indented properly. Any work around for this, thanks a lot.

    M 1 Reply Last reply
    0
    • R Randal Vance Cunanan

      Need help on the format of the produced output of the HtmlWriter class. I need to make properly indent the tags in the final rendered output. Sample:

      string[] Names = new string[]
      {
      "Johnny",
      "Mindy",
      "Jossy",
      "Kreuger",
      "Marco"
      };

              HtmlTextWriter writer = new HtmlTextWriter(new StringWriter());
              writer.RenderBeginTag(HtmlTextWriterTag.Ul);
              foreach (string name in Names)
              {
                  writer.RenderBeginTag(HtmlTextWriterTag.Li);
                  writer.Write(name);
                  writer.RenderEndTag();
                  writer.WriteLine();
              }
              writer.RenderEndTag();
      

      The produced output is this:

      <ul>
          <li>Johnny</li>
          <li>Mindy</li>
          <li>Jossy</li>
          <li>Kreuger</li>
          <li>Marco</li>
      </ul>

      The closing ul tag is not indented properly. Any work around for this, thanks a lot.

      M Offline
      M Offline
      Martin Jarvis
      wrote on last edited by
      #2

      This looks like some whitespace is rendered before the code snippet you've provided. If this is from the Render method of a control, it may be whitespace introduced in the designer.


      Freestyle Interactive Ltd | Martin on .Net

      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