How to render a page

H

Heron

Hi,

I need to render my site for html 3.2 so I ran into to Html32TextWriter and
managed to render some usercontrols but how do you create an actual page?

In the default.aspx I tried to create my login page like this.

protected void Page_Load(object sender, EventArgs e)
{
rendered = new StringBuilder();
this.LoginMainTest1 = new _LoginMainTest();
System.IO.TextWriter txtwriter = new System.IO.StringWriter(rendered);
Html32TextWriter html32writer = new Html32TextWriter(txtwriter);
Page pg = new Page();
pg.Controls.Add(this.LoginMainTest1);
pg.RenderControl(html32writer);
//.......
}

this gives an error 'Request is not available in this context' on
pg.RenderControl(html32writer); so does anyone got a nice "Hello world"
example on how to make such a page?
 
M

Matthias Pieroth

Hello Heron,

Heron said:
Hi,

I need to render my site for html 3.2 so I ran into to Html32TextWriter
and managed to render some usercontrols but how do you create an actual
page?

In the default.aspx I tried to create my login page like this.

protected void Page_Load(object sender, EventArgs e)
{
rendered = new StringBuilder();
this.LoginMainTest1 = new _LoginMainTest();
System.IO.TextWriter txtwriter = new System.IO.StringWriter(rendered);
Html32TextWriter html32writer = new Html32TextWriter(txtwriter);
Page pg = new Page();

Don't do that. You already have a page. Try "this.Page", you'll see...
pg.Controls.Add(this.LoginMainTest1);

Add the control to a Form that has the Attribute runat=server.
pg.RenderControl(html32writer);

You don't need to call this manually!

Bye,
 
H

Heron

hmm, tried it several ways now and i still fail to get it validated for html
3.2.

My current page looks like this but it's not working like you can see at
http://validator.w3.org/check?uri=h...arset=(detect+automatically)&doctype=HTML+3.2

<%@ Page Language="C#" %>
<%@ Register Src="Controls/LoginMainTest.ascx" TagName="LoginMainTest"
TagPrefix="uc1" %>
<script runat="server">
protected override HtmlTextWriter
CreateHtmlTextWriter(System.IO.TextWriter writer)
{
return new Html32TextWriter(writer);
}
</script>
<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:LoginMainTest ID="LoginMainTest1" runat="server" />
</div>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,129
Latest member
FastBurnketo
Top