Click here to Skip to main content
14,495,596 members
Rate this:
Please Sign up or sign in to vote.
See more:
I use this sir and I get these pages one below another.
I want to set the time for display one bye one only in one window
display webpages in one page one by one with 10 sec gap using timer control
to set time

WebRequest req = WebRequest.Create("http://www.google.com");
WebRequest req2 = WebRequest.Create("http://www.princemahesh.com");
WebResponse resp1 = req2.GetResponse();
Stream s1 = resp1.GetResponseStream();
StreamReader sr1 = new StreamReader(s1, Encoding.ASCII);
string doc1 = sr1.ReadToEnd();
Label2.Text = doc1;

WebResponse resp = req.GetResponse();

Stream s = resp.GetResponseStream();
StreamReader sr = new StreamReader(s,Encoding.ASCII);
string doc = sr.ReadToEnd();

Label1.Text = doc;
Posted
Updated 8-Nov-10 22:22pm
v5
Comments
E.F. Nijboer 5-Nov-10 8:13am
   
It's not completely clear what you want exactly. Could you try to add some extra information and explain what you want exactly. Maybe add an example of the output you would want to get? You can use "Improve question" to add this additional information.
shakil0304003 5-Nov-10 11:44am
   
Not clear!!!
Rate this:
Please Sign up or sign in to vote.

Solution 2

Look into use asnyc methods like WebRequest.BeginGetResponse[^] this way when the first BeginGetResponse() completes start a timer so that 10seconds later another BeginGetResponse() begins for the second address.

I do have to say that the need to show one site then another 10seconds later through code makes no sense, if this is for a demo use something like camtasia[^] to record the output and what to do.
   
Comments
shakil0304003 5-Nov-10 11:46am
   
I think this answer is correct & useful.
Rate this:
Please Sign up or sign in to vote.

Solution 1

Maybe it would simply work by using Response.Write and Response.Flush.

Something like:
Response.Write(doc1);
Response.Flush;
Sleep(10000);
Response.Write(doc2);


Good luck!
   
Comments
Rod Kemp 5-Nov-10 11:00am
   
Your answer makes no sense, the question is showing CLIENT side code, think browser, your answer is using SERVER side response.
shakil0304003 5-Nov-10 11:44am
   
I agree with Rod kemp.
E.F. Nijboer 5-Nov-10 15:03pm
   
You both agree that the code in the question above is CLIENT SIDE CODE??? Well, very interesting. The question is about ASP.NET, C# and I don't think there is a browser that has direct support for that. Also, the link you (Rob Kemp) gave is also SERVER SIDE CODE. It would normally not even work on the client side because it would be considered "cross-site-scripting". So, also to you... Good luck! ;-)
Rod Kemp 6-Nov-10 8:53am
   
You need to look closer at the WebRequest and WebResponse classes, these have no bearing on the Request and Response objects used within an ASP.Net website. If you would also look at the OP question it mentions that the OP is GETTING the pages using the specified code this puts it in the realm of client side code. As a final point it is possible to get responses from a web server using the .Net framework without using a browser, so I may have miss spoke and should have said "think a C# app in place of a browser". Maybe you need to look beyond the classic browser/web server relationship. Good luck! ;-)
E.F. Nijboer 7-Nov-10 9:23am
   
Ah, I understand what you mean. I was thinking, because the question is about ASP.NET, C#, of a website that would load other sites and return those to a client browser. As ASP.NET is for hosting websites so I thought the problem would be that the 10 second wait (without a flush) would simply show nothing during that waiting period. In that case it's just the interpretation of the question that went somewhat wrong I guess :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100