473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 5434
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Paul Thompson | last post by:
In NN/FF/Moz, it takes 20 sec to render a page from a file of 330 KB. It takes less than 1 sec to render that file in IE. Is there some tweak that I can make on NN to alter this? The...
11
by: William Buch | last post by:
I have a strange problem. The code isn't written by me, but uses the qsort function in stdlib. ALWAYS, the fourth time through, the memory location of variable list (i.e. mem location = 41813698)...
2
by: Pramod | last post by:
Hello All We have application here. That utilizes the CrsytalReport.net. We have initial version installed on Production server where all report pages opening fine. Now we have added some changes...
4
by: AndrewV | last post by:
I have an html page that has 2 frames ("input" and "result"). In the "input" frame, there is a text box and a button. User enters an id in the text box, then click on the button. In the click...
2
by: Jeronimo Bertran | last post by:
I have an aspx page that shows a complex image with several objects that are sensitive to mouseover events. The information about the objects in the image is obtained from a database and complex...
0
by: paulhux174 | last post by:
I'm trying to send several emails using the webpage by getting a string copy of it using the RenderControl() function of System.Web.UI.Page. I've added code below Program logic is: hide some...
4
by: JJA | last post by:
Previously, anything IE did not like threw some sort of error like "object expected", etc. Now all I get is "Done" on the status bar... I am suddenly having trouble with Internet Explorer. Both...
1
by: farghal | last post by:
Hello as many people I'm new to ajax but trying my best to understand. At this point I got a problem I'm not able to solve. I've looked on several forums and googled internet but I can't find a...
10
by: Daniel Peterson | last post by:
I'm responsible for a pair of IIS 6 webservers that run our production ASP.Net application. We push code on a monthly basis, and about two weeks after our October code push, we started to run into...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.