We help IT Professionals succeed at work.

Adding something to the response that comes back

Tom Knowlton
Tom Knowlton asked
on
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;
                try
                {
                    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 = "";
                        try
                        {
                            html = reader.ReadToEnd();
                        }
                        finally
                        {
                            reader.Close();
                        }


//                        <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>
//</select>
                        
                    }
                    else
                    {
                        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!
Comment
Watch Question

Commented:
Well...I can think of a couple of ways conceptually to handle this, depending on the specifics. I think it's more a matter of timing then whether or not jQuery can calculate and add things to the page -- it can definitely do that.

1. If you're re-writing the entire page, you could have a DOM ready function (e.g., $(readyFunction()) ) in that page that checks to see if the added HTML is there and then does the calculations / additions.

2. You could add a callback function to the code that gets the new HTML which fires when the receipt is complete and then does the calculations / additions at that time.

HTH

Tom KnowltonWeb developer

Author

Commented:
thx

Commented:
You're welcome; glad that helped... and thanks for the points!
Tom KnowltonWeb developer

Author

Commented:
yep!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.