hello,
is there a way to programmatically loadup one of your .aspx pages, as
if it had been rendered to an actual request?
something like:
//create the page in memory
SomePage somePage = new SomePage();
//prep the writers
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
//render the page
somePage.RenderControl(htw);
//snag its html
string bodyHTML = sb.ToString();
....is there a way to do this? the above doesnt really do anything. the
bodyHTML appears always empty.
im aware of the WebRequest technique, whereby i pass in the page's URL
and get its response streamed back. however, that has a drawback in
that Session is lost.
i need a way for one webpage to get another webpage's content, and that
content is based on somethings that must be passed via any state
method. session, cookie, whatever works. except the querystring -- i
believe theres a character-limit on the QS, and i dont want to even
worry about hitting it.
thanks!
matt 7 2437
m...@mailinator.com wrote:
...is there a way to do this? the above doesnt really do anything. the
bodyHTML appears always empty.
in fact, w/ the above, the debug break points ive set in teh MyPage
code-behind dont even get hit. odd.
matt
Place the logic in a user control, and follow the code at: http://openmymind.net/FAQ.aspx?documentId=45
-- http://www.openmymind.net/ http://www.fuelindustries.com/
<ma**@mailinator.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
>
m...@mailinator.com wrote:
>...is there a way to do this? the above doesnt really do anything. the bodyHTML appears always empty.
in fact, w/ the above, the debug break points ive set in teh MyPage
code-behind dont even get hit. odd.
matt
Karl Seguin [MVP] wrote:
Place the logic in a user control, and follow the code at: http://openmymind.net/FAQ.aspx?documentId=45
yes, thats the same technique i have above. i can and have done that
for controls, but there are two problems w/ it:
1) in the case i have in mind, i want the entire end-result-HTML of a
..aspx page. the final HTML, after all its controls have rendered, as it
would be if being sent back to an actual web browser. not just one
control's.
2) the user-control technique is, to the best of my knowledge, flawed.
if you try to render a usercontrol that contains one or more child
server-side controls such as a dropdownlist or repeater, then it will
break -- saying that the usercontrol's children must be w/i a <form>
tag. simply, it will not let you programatically render a usercontrol
containing children controls. see this thread: http://tinyurl.com/ortqr
....so the question remains: is there no way to render a .aspx page into
a string?
btw, regarding the above #2 -- do you have a workable solution for
this? thats been another challenge..
thanks,
matt
you are on the right track, but calling render is not enough, as this will
not fire page load, load viewstate session state, etc. you need to call
ProcessRequest(HttpContext) where you build your own context. care will be
needed with session as its serialized, so you need to supply your own
session manager.
-- bruce (sqlwork.com)
<ma**@mailinator.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
hello,
is there a way to programmatically loadup one of your .aspx pages, as
if it had been rendered to an actual request?
something like:
//create the page in memory
SomePage somePage = new SomePage();
//prep the writers
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
//render the page
somePage.RenderControl(htw);
//snag its html
string bodyHTML = sb.ToString();
...is there a way to do this? the above doesnt really do anything. the
bodyHTML appears always empty.
im aware of the WebRequest technique, whereby i pass in the page's URL
and get its response streamed back. however, that has a drawback in
that Session is lost.
i need a way for one webpage to get another webpage's content, and that
content is based on somethings that must be passed via any state
method. session, cookie, whatever works. except the querystring -- i
believe theres a character-limit on the QS, and i dont want to even
worry about hitting it.
thanks!
matt
Hi Matt
Here is a method I use
StringWriter _writer = new StringWriter();
Context.Server.Execute("MyPage.aspx" _writer);
You'll then have a StringWriter with the HTML inside.
Hope this helps.
Regards
Ray ma**@mailinator.com wrote:
hello,
is there a way to programmatically loadup one of your .aspx pages, as
if it had been rendered to an actual request?
something like:
//create the page in memory
SomePage somePage = new SomePage();
//prep the writers
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
//render the page
somePage.RenderControl(htw);
//snag its html
string bodyHTML = sb.ToString();
...is there a way to do this? the above doesnt really do anything. the
bodyHTML appears always empty.
im aware of the WebRequest technique, whereby i pass in the page's URL
and get its response streamed back. however, that has a drawback in
that Session is lost.
i need a way for one webpage to get another webpage's content, and that
content is based on somethings that must be passed via any state
method. session, cookie, whatever works. except the querystring -- i
believe theres a character-limit on the QS, and i dont want to even
worry about hitting it.
thanks!
matt
Ray Booysen wrote:
Here is a method I use
StringWriter _writer = new StringWriter();
Context.Server.Execute("MyPage.aspx" _writer);
yep, thats it! like so:
StringWriter writer = new StringWriter();
Server.Execute(""somePage.aspx", writer);
string bodyHTML = writer.ToString();
....and that grabs it. more, it also maintains state between the two!
excellent!
thanks,
matt
Glad this helps.
Just make sure you handle any exceptions that the Execute() method
throws. If I remember correctly if there is an exception thrown in the
page you are executing, there is a generic exception thrown by the
Execute() method that you would need to handle.
Regards
Ray ma**@mailinator.com wrote:
Ray Booysen wrote:
>Here is a method I use
StringWriter _writer = new StringWriter(); Context.Server.Execute("MyPage.aspx" _writer);
yep, thats it! like so:
StringWriter writer = new StringWriter();
Server.Execute(""somePage.aspx", writer);
string bodyHTML = writer.ToString();
...and that grabs it. more, it also maintains state between the two!
excellent!
thanks,
matt This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John Spiegel |
last post by:
Hi all,
I think this is a longshot, but is there a technique for programmatically
run a webpage?
Let's say one of our vendors has a page that we go to daily to pick up some
files. Each time,...
|
by: ALthePal |
last post by:
Hi,
I'm not sure if we are able to or even how to loop through the web forms in
a VB.NET project during design time. In MSAccess we are able to go through
the database -> forms collection and...
|
by: jrefactors |
last post by:
How to extract data from html page? For example, if i want to
get the information of weather
(http://weather.yahoo.com/forecast/USCA1005.html)
and put in my web page. Is it possible to do that?
...
|
by: Selen |
last post by:
I would like to be able to extract a BLOB from the database (SqlServer)
and pass it to a browser without writing it to a file. (The BLOB's
are word doc's, MS project doc's, and Excel spreadsheets....
|
by: Vjay77 |
last post by:
I posted this question, but I pressed 'post' and it disappeared. So
once again:
Problem:
I need to go to lets say www.site.com/page.html
Imagine that this html code is 6 mb long.
I need to...
|
by: rahman |
last post by:
I have few hundred HTML pages.
I need to extract portion of each HTML page into a text/database/HTML
files format. You can imagine it is very tedious to do one by one.
Is there any automatic...
|
by: TB |
last post by:
Hi All:
I have this page where a rows / cells are programmatically added to to table
by pushing a button.
The rows contain a textbox and a associated button. What I want to is to be
able to...
|
by: ChrisCicc |
last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
|
by: =?Utf-8?B?QW5nZWw=?= |
last post by:
I seem to understand how the control works as long as I mated to
SqlDataSource or ObjDataSource it works fine. But I do not want to flatten
my design in this manner. I am interested in how I can...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |