473,651 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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><a sp:Label id=label
Runat=server/>...");
aPage.Control.A dd(lc)
aPage.RenderCon trol(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 5452
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.new s.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><a sp:Label id=label
Runat=server/>...");
aPage.Control.A dd(lc)
aPage.RenderCon trol(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.new s.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><a sp:Label id=label
Runat=server/>...");
aPage.Control.A dd(lc)
aPage.RenderCon trol(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.new s.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><a sp:Label id=label
Runat=server/>...");
aPage.Control.A dd(lc)
aPage.RenderCon trol(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:DataG rid 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
1612
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 difference is absolutely annoying and unacceptable.
11
2847
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) becomes 11, then the program crashes. It is obviously qsort that may me overwritten the used memory location. The weird thing is that it is ALWAYS the fourth time running the program. Below is the code MEMORY LOCATION OK HERE for (i = 0; i...
2
7141
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 apart from report and compiled soluion and put that code on production first page of report gives error 'Fail to render page.' Root cause i found out i.e. because of image on that page but other pages work fine as there are no images on that. But if we...
4
4172
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 event, I would like to call an asp.net page, and passing in the text box value as a query string parameter (http://mysite/mypage.aspx?id=x) and display the result in the "result" frame. I couldn't find a way to do it. Please give me some pointer on how...
2
1436
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 calculations are performed for each object to determine the position within the image. To render the image I created an aspx page that uses the following code to render the image: Response.ContentType = "image/jpeg";...
0
876
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 buttons and labels and controls, render page send email, Then hide other parts, show other parts, render again (fails here with "A page can have only one server-side Form tag."),
4
2142
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 IE 7 and IE 6 behave the same way - they fail to render the page at all yet do not seem to be detecting any errors on the client side. No errors occur on the web server either. I've issued VIEW SOURCE on this blank IE screen and captured it to a...
1
9010
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 solution :S. This is the basic idea: I'm trying to implement Ajax in a Portal page created in weblogic 9.2. I've created a portlet with the name Ajax.jsp and an additional page called test.jsp. Ajax.jsp is the main portlet page. And uses the...
10
6677
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 occasional webserver errors. The application pool is configured to run as a domain user which has permissions to the web code. When we have issues, the webserver will return the ASP.Net "Server Application Unavailable" page, and our app pool...
0
8347
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8792
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7294
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4280
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1905
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.