1

I'm trying to write HTML code into my ASPX file from my C# file. This is what I have so far, just to try to get it working before I actually starting putting in stuff that I want.

protected void Page_Load(object sender, EventArgs e)
{
    StringWriter sw = new StringWriter();
    HtmlTextWriter writer = new HtmlTextWriter(sw);

    writer.WriteBeginTag("p");
    writer.Write("THERE IS STUFF HERE");
    writer.WriteEndTag("p");
}

If my code up to this point is correct, then I assume I need some line of code that actually tells it to write, or something like that. However, I don't know what that is.

Also, if I get this working, what part of the page will it write to? Is there any way to tell it where to write?

4

1 回答 1

1

您的代码正在编写 HTML。但它正在将其写入您的StringWriter,这不是您的想法。

尝试将其写入Response.Output

仅供参考,您最好将这种代码从 Page_Load 中取出并改用用户控件。

于 2014-04-09T01:05:52.303 回答