System.Web.UI.Control 中 HtmlTextWriter 的替代品?
您可以在 Web 应用程序用户控件中使用 FluentHTML 或其他替代方案吗?
您能否将标记文件像 System.Web.UI.UserControl 一样放入 System.Web.UI.Control 中,但没有 Page 对象的负担?
我想减少以下代码的行数:
writer.Write(SacrificalMarkupPage.GenerateControlMarkup(new DialogConfirm()));
writer.AddAttribute("class", string.Format("ajaxResponse {0}", action));
writer.RenderBeginTag("div");
writer.RenderBeginTag("h4");
writer.WriteEncodedText("Delete selected item?");
writer.RenderEndTag(); //h4
var queryString = new HttpQueryString
{
{"confirmed", "true"},
{"src", urlReferer.PathAndQuery}
};
writer.AddAttribute("href", queryString.MakeQueryString(url).PathAndQuery);
writer.AddAttribute("class", "delete");
writer.RenderBeginTag("a");
writer.WriteEncodedText("Yes");
writer.RenderEndTag(); //a.delete
writer.WriteEncodedText(" | ");
writer.AddAttribute("href", urlReferer.PathAndQuery);
writer.AddAttribute("class", "back");
writer.RenderBeginTag("a");
writer.WriteEncodedText("No");
writer.RenderEndTag(); //a.back
writer.RenderEndTag(); //div.ajaxResponse.ACTION
谢谢
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 the burden of the Page object?
I would like to reduce the number of lines of the following code:
writer.Write(SacrificalMarkupPage.GenerateControlMarkup(new DialogConfirm()));
writer.AddAttribute("class", string.Format("ajaxResponse {0}", action));
writer.RenderBeginTag("div");
writer.RenderBeginTag("h4");
writer.WriteEncodedText("Delete selected item?");
writer.RenderEndTag(); //h4
var queryString = new HttpQueryString
{
{"confirmed", "true"},
{"src", urlReferer.PathAndQuery}
};
writer.AddAttribute("href", queryString.MakeQueryString(url).PathAndQuery);
writer.AddAttribute("class", "delete");
writer.RenderBeginTag("a");
writer.WriteEncodedText("Yes");
writer.RenderEndTag(); //a.delete
writer.WriteEncodedText(" | ");
writer.AddAttribute("href", urlReferer.PathAndQuery);
writer.AddAttribute("class", "back");
writer.RenderBeginTag("a");
writer.WriteEncodedText("No");
writer.RenderEndTag(); //a.back
writer.RenderEndTag(); //div.ajaxResponse.ACTION
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,只需使用 HtmlTextWriter.Write并将 FluentHTML 返回的任何内容传递给它:
FWIW,WebForms 方式是使用现有的服务器或 Html 控件并将它们呈现出来。如果您只是将一堆硬编码文本串在一起,您可能应该将其硬编码:
Sure, just use HtmlTextWriter.Write and pass it whatever FluentHTML gives you back:
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:
我开发了自己的辅助工具,现在我可以这样编写标记:
在本例中,块标签的第一个参数是 ID,第二个参数是类,最后一个参数是对编写器的引用
I developed my own helper tools, now i can write markup this way:
in this example, the first parameter of a blocktag is the ID, the second the class, the last a reference to the writer