Reputation: 118
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?
Upvotes: 2
Views: 818
Reputation: 161831
Your code is writing HTML. But it's writing it to your StringWriter
, which is not what you had in mind.
Try writing it to Response.Output
instead.
FYI, you would do better taking that sort of code out of Page_Load and using a User Control instead.
Upvotes: 2