468,107 Members | 1,311 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

Is this possible to render page in memory?

Hi

I want to render a page in memory. That is (pseudo-code):

Page aPage = new Page();
LiteralControl lc =
new LiteralControl("<form runat=server><asp:Label id=label
Runat=server/>...");
aPage.Control.Add(lc)
aPage.RenderControl(htmlWriter);

Unfortunately, this does not work, as the page does not go through its
lifecycle (Init, Load...). So it does not know about inner controls. In fact
RenderControl does work, but the result is the text I provided to
LiteralControl because no control is instantiated - this is just a plain
text for server.

What I actually want to do is to load page template from database and render
it.

Is there a way to "run" the page in such a way as IIS does? Or: is there a
way to force Page instance to go through lifecycle?

Regards.

Mar 21 '06 #1
5 5099
Do a google search for "screen scraping asp.net"

This is what you're after I think.

"Piotr Strycharz" <Pi*************@antispam-account.com> wrote in message
news:dv**********@atlantis.news.tpi.pl...
Hi

I want to render a page in memory. That is (pseudo-code):

Page aPage = new Page();
LiteralControl lc =
new LiteralControl("<form runat=server><asp:Label id=label
Runat=server/>...");
aPage.Control.Add(lc)
aPage.RenderControl(htmlWriter);

Unfortunately, this does not work, as the page does not go through its
lifecycle (Init, Load...). So it does not know about inner controls. In fact RenderControl does work, but the result is the text I provided to
LiteralControl because no control is instantiated - this is just a plain
text for server.

What I actually want to do is to load page template from database and render it.

Is there a way to "run" the page in such a way as IIS does? Or: is there a
way to force Page instance to go through lifecycle?

Regards.

Mar 21 '06 #2
Why don't you have a page that actually renders what you want to and
then send a web request to this page. Store the response stream in a
memory stream and you should be good to go.

Mar 21 '06 #3
you can create your own httpcontext and call ProcessRequest(httpcontext).

-- bruce (sqlwork.com)

"Piotr Strycharz" <Pi*************@antispam-account.com> wrote in message
news:dv**********@atlantis.news.tpi.pl...
Hi

I want to render a page in memory. That is (pseudo-code):

Page aPage = new Page();
LiteralControl lc =
new LiteralControl("<form runat=server><asp:Label id=label
Runat=server/>...");
aPage.Control.Add(lc)
aPage.RenderControl(htmlWriter);

Unfortunately, this does not work, as the page does not go through its
lifecycle (Init, Load...). So it does not know about inner controls. In
fact
RenderControl does work, but the result is the text I provided to
LiteralControl because no control is instantiated - this is just a plain
text for server.

What I actually want to do is to load page template from database and
render
it.

Is there a way to "run" the page in such a way as IIS does? Or: is there a
way to force Page instance to go through lifecycle?

Regards.

Mar 21 '06 #4
As I am always saying everything possible - depends how much money you have
:)

In this case you can get away easy. I am using similar system for my email
templates.

It's hard to do what you want with the Page but easy with UserControl which
is pretty much the same.
Create UserControl (let say EmailTemplate).

Then in your ASP.NET page you can use following code

EmailTemplate t = (EmailTemplate)LoadControl("~/templates/mytemplate.ascx");
t.var1 = "aaaa";
t.label1 = "bbbb";
StringWriter we = new StringWriter();
HtmlTextWriter wr = new HtmlTextWriter(we);
t.RenderControl(wr);
string sHtmlText = we.ToString();

George
George
"Piotr Strycharz" <Pi*************@antispam-account.com> wrote in message
news:dv**********@atlantis.news.tpi.pl...
Hi

I want to render a page in memory. That is (pseudo-code):

Page aPage = new Page();
LiteralControl lc =
new LiteralControl("<form runat=server><asp:Label id=label
Runat=server/>...");
aPage.Control.Add(lc)
aPage.RenderControl(htmlWriter);

Unfortunately, this does not work, as the page does not go through its
lifecycle (Init, Load...). So it does not know about inner controls. In
fact
RenderControl does work, but the result is the text I provided to
LiteralControl because no control is instantiated - this is just a plain
text for server.

What I actually want to do is to load page template from database and
render
it.

Is there a way to "run" the page in such a way as IIS does? Or: is there a
way to force Page instance to go through lifecycle?

Regards.

Mar 21 '06 #5

Użytkownik "Piotr Strycharz" <Pi*************@antispam-account.com> wrote
I want to render a page in memory. That is (pseudo-code):


Unfortunately, almost no one has read my message carefully. The simple
RenderControl or loading it through WebRequest won't work, because Page is
initially empty and has to load its content as string. Thus no parsing
occurs and no control hierarchy is created.
I cannot do:
aPage.Controls.Add(datagrid);
which can be processed, but I have to do (pseudo):
aPage.InnerHtml = "<asp:DataGrid ID=grid Runat=server/>";

The only thing seems to be checking proposed ProcessRequest method.

Piotr.

Mar 22 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Paul Thompson | last post: by
11 posts views Thread by William Buch | last post: by
2 posts views Thread by Pramod | last post: by
4 posts views Thread by AndrewV | last post: by
2 posts views Thread by Jeronimo Bertran | last post: by
reply views Thread by paulhux174 | last post: by
10 posts views Thread by Daniel Peterson | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.