LiteralControlBuilder any example?
I have been using LiteralControl
to 开发者_开发问答add direct HTML code to webpages for long time, but I just found out about LiteralControlBuilder
. I first thought it would be a mix of StringBuilder
and LiteralControl
, but apparently is not. The code below compiles but crashes when executing.
LiteralControlBuilder builder = new LiteralControlBuilder();
builder.AppendLiteralString("<div>");
builder.AppendLiteralString("<p>" + speech.Text + "</p>");
builder.AppendLiteralString("<p>" + speech.From + "(" + speech.When + ")</p>");
builder.AppendLiteralString("</div>");
Controls.Add(new LiteralControl(builder.ToString()));
The exception is at the line builder.AppendLiteralString("<div>");
and the message is:
Property '' does not have a property named 'text'.
Any idea how to use it?
The ASP.NET parser uses this class to generate HTML for any Literal controls on a requested Web Forms page. You will not need to use this class directly in application code.
http://learning.infocollections.com/ebook%202/Computer/Programming/ASP.Net/ASP.NET.in.a.Nutshell.Second.Edition/0596005202_ch42-77213.html
- There is a method Init you have to call first.
精彩评论