473,320 Members | 2,092 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.

Reading Current Page XHTML

yarbrough40
320 100+
Gang, this is driving me nuts - In a given asp.net page which I have loaded, I would like to read through the XHTML code of that page into a string (that I can do whatever I want with) and for the life of me I cannot figure out how to get at that XHTML page code.

I naturally assumed that I could use some function existant in the httprequest / response spaces, but I'm coming up empty. I have to believe that this cannot be that hard and I'm missing something simple here. You would be my personal hero if you could share some insight with me.
May 12 '10 #1
3 1058
Curtis Rutland
3,256 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.google.com");
  2. HttpWebResponse res = (HttpWebResponse)req.GetResponse();
  3. StreamReader reader = new StreamReader(res.GetResponseStream());
  4. string content = reader.ReadToEnd();
  5. reader.Close();
  6. Console.WriteLine(content);
Does this do what you need? This gets all the text in the stream and dumps it into a string.
May 12 '10 #2
yarbrough40
320 100+
well- what you have does work. My problem comes in, though when the controls on the target page are not rendered until the user inputs his parameters and clicks a button. So simply sending the url ("http://www.mypage.aspx") will not fit the bill. I will somehow need to grab the html at runtime on a button click on the page itself when all the controls have rendered to the page.

I'm thinking maybe using the RenderControl method to yank the raw html from the page.... not sure
May 12 '10 #3
yarbrough40
320 100+
ok so I found a solution that fits my needs.... RenderControl() is the key. It is of my opinion that this is a mega-useful thing to know.

if anyone cares this is how I did it.

FIRST you use RenderControl to extract the raw html out of a given control you specify. It could be the entire form if you want. In this example I am grabbing two Label controls. THEN you store that html in a stringbuilder.

Expand|Select|Wrap|Line Numbers
  1. Button_Click()
  2.  
  3.         Dim c1 As Control = Label1
  4.         Dim c2 As Control = Label2
  5.  
  6.         Dim sb As New StringBuilder
  7.         Dim sr As New StringWriter(sb)
  8.         Dim htr As New System.Web.UI.HtmlTextWriter(sr)
  9.  
  10.  
  11.         c1.RenderControl(htr)
  12.         c2.RenderControl(htr)
  13.  
  14.     End Sub
Now you have a string value --> (sb.ToString) that you can do whatever you want with.

ENJOY!
May 14 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: JT | last post by:
is there a command in asp to get the name of the current page? furthermore, is there a way to retrieve the name of the current page within an 'included' file (not the name of the included page,...
1
by: mvr | last post by:
Hi all Is there any way I can print the current page(page1.asp) and another page(page2.asp) from the current page(page1.asp). Any code or suggestions will be appreciated. Thanks mvr
8
by: Dan | last post by:
When a user clicks on a link in my menu, I want the background color of the link that comes up in the hover to remain on the destination page. My menu looks like this: <div id="adminmenu"> <a...
10
by: Kerberos | last post by:
Is there a way to change the color of a link in a navbar if the address of the link is the current page? For instance if I have: Home - index.php Products - products.php Contact - contact.php...
4
by: Sandy Bremmer | last post by:
I am wondering if the following can be accomplished with javascript (and if so, if you think javascript is an appropriate solution). I'm afraid my javascript skills lack. I need to build a...
3
by: Carolyn Vo | last post by:
I have a datagrid in my web control class that I am trying to get the current rows displayed for. I have enabled paging on the datagrid so if the user is currently on page 3 of 8, and if I have...
2
by: Brian Henry | last post by:
Hi, I have a data grid that is set up like this Page items displayed = 10 EnableViewState = false (i dont want to send large amounts of data over the internet!) CustomPaging = false...
3
by: Rhino | last post by:
Yesterday, I reworked the index on my site - http://sfl.london.on.ca - so that they used list markup and I'm quite pleased with them. However, I'm having a problem with one small aspect of the menu...
1
by: Mayhul | last post by:
Hi there, Does anyone know where I can find information about Reading current connection value from performance counters into ASP page. I wanted to know how I can call the current connection...
3
by: elyob | last post by:
Hi, I'm just wondering how I change some css text when I mouseover a picture. At the moment document.write just writes to a new page. function displayname(name) { document.write(name); }
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.