We help IT Professionals succeed at work.
Get Started

Adding something to the response that comes back

Tom Knowlton
Tom Knowlton asked
Last Modified: 2012-05-12
I am running the following code in a C# windows application:

 foreach (string site in websites)
                //CampusWebstoreWebService.WebGlobalMethodsSoapClient wbmsc = new CampusWebstoreWebService.WebGlobalMethodsSoapClient();

                //bool isavail = wbmsc..NameIsAvailable("max");

                string sitetemp = site + "/booksearch.aspx";

                HttpWebRequest request = null;
                Uri uri = new Uri(sitetemp);
                request = (HttpWebRequest)WebRequest.Create(uri);
                string siteup = "";
                HttpWebResponse response = null;
                    response = (HttpWebResponse)request.GetResponse();
                    if (response.StatusCode == HttpStatusCode.OK)
                        siteup = "site is up (" + response.StatusCode.ToString() + ")";
                        Stream responseStream = response.GetResponseStream();
                        StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                        string html = "";
                            html = reader.ReadToEnd();

//                        <select name="ctl00$ContentPlaceHolder1$dlStore" id="ctl00_ContentPlaceHolder1_dlStore" disabled="disabled" title="Store" style="text-align: left">
//            <option value="NULL">Select Campus...</option>
//            <option selected="selected" value="1">KSU ASHTABULA</option>
                        siteup = "site may have a problem (" + response.StatusCode.ToString() + ")";
                catch (System.Net.WebException we)
                    siteup = ".......................... 404 site not found";


                textBoxStatusMessagesWebsites.Text += site + " ... " + siteup + System.Environment.NewLine;

Open in new window

Essentially what it is doing is programmatically requesting a web page...getting the response...and then reading in the HTML into a string variable.

This works fine, but my question is this:

Is there a way for javascript to ADD SOMETHING to the HTML that is coming back in the response, such that I could summarize information about the HTML sent back without having to parse the HTML?

More to the point....I know that jQuery can do things like count how many <div> tags there are on a web page and then modify the DOM to display the count ( like put the count into a textbox or something).  Can such information be added to the response HTML that comes back?

I hope this makes sense.

If JavaScript / jQuery cannot help with this  (perhaps they run too late in the web page creation to be of use) then my next question would be....could ASP.NET do something on the server side to provide the same information in the response?  I am thinking yes it could.

I would favor a JavaScript / jQuery way to do this, because then I could modify the .js file without having to re-compile the site code...this would be a lot less intrusive and much easier to deploy.

Thank you!
Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE