Are there any benefits to using HtmlTextWriter if you are not going to benefit from adaptive rendering?

后端 未结 5 1258
北恋
北恋 2021-02-07 11:17

Outside of benefiting from Adaptive Rendering for alternate devices, does it ever make sense to write all of this code:

writer.WriteBeginTag(\"t         


        
5条回答
  •  一整个雨季
    2021-02-07 11:54

    At some point, you still need to pass this to a HtmlTextWriter in order to render to the client. I guess you would have a final writer.Write(sb.ToString()); in there in the second example. What you can do to reduce the lines of code is writing raw HTML, exactly the same way as in your second StringBuilder example, but using HtmlTextWriter.Write instead.

    writer.Write("
    "); writer.Write(someTextVariable); writer.Write("
    ");

    Then using a StringBuilder seems unnecessary. And, HtmlTextWriter will, at least to some extent, make sure the generated HTML is compliant(although that is not true in the above case, when writing raw HTML).

提交回复
热议问题