Alternatives To Htmltextwriter In A System.web.ui.control?
Can you use FluentHTML or other alternatives in an web application user control? Can you put a markup file in a System.Web.UI.Control like the System.Web.UI.UserControl but without
Solution 1:
Sure, just use HtmlTextWriter.Write and pass it whatever FluentHTML gives you back:
writer.Write(
Html.TextBox(m => m.Chapter.Slug).Class("required").Title("Slug")
);
FWIW, the WebForms way would be to use the existing Server or Html controls and render those out instead. If you're just stringing together a bunch of hardcoded text, you should probably just hardcode it:
writer.Write(
@"<div><h4>Delete selected item?</h4></div>"
);
Solution 2:
I developed my own helper tools, now i can write markup this way:
using (new Xhtml.BlockTags.Body(writer))
{
using (new Xhtml.BlockTags.Div("layout", string.Empty, true, writer))
{
using (new Xhtml.BlockTags.Div("header", string.Empty, writer))
{
_header.Render(writer);
}
using (new Xhtml.BlockTags.Div("content", string.Empty, writer))
{
_content.Render(writer);
}
AjaxStatus.Render(writer);
}
}
in this example, the first parameter of a blocktag is the ID, the second the class, the last a reference to the writer
Post a Comment for "Alternatives To Htmltextwriter In A System.web.ui.control?"