Last post Dec 27, 2006 01:19 AM by jessjing
Dec 26, 2006 08:32 PM|asppick|LINK
I want put some delay time (lets say for 30sec) before redirecting to another page..
If S="One" then
'Do Something here
'Here I want to display something on this page and have some delaytime for 30 sec, so that user can read that
lblMessage.text = "Going to redirect to page First.aspx in 30 Secs"
Dec 26, 2006 09:05 PM|XIII|LINK
instead of the Response.Redirect you need to show something in the browser, thus you need some html redirect mechanism. You can put in the <head> tag a Literal control of which you can set the text, or in ASP.NET 2.0 I believe it's also possible to add dynamic
<meta> tags directly.
<meta http-equiv="refresh" content="30;url=First.aspx">
Dec 27, 2006 01:19 AM|jessjing|LINK
look at this
Many ASP.NET developers find that despite their best efforts in producing efficient code that minimizes response times, the vagaries of database response times, the transit time over the Internet, and user input criteria that are not specific enough can
result in a lengthy delay before a page appears in the browser. The result is that users often click the submit button several times to try to elicit a response from your server, sometimes causing all kinds of unfortunate side effects.
Chapter 6, "Client-Side Script Integration," looks at some specific solutions for creating a one-click button. However, an alternative approach is to provide a page that loads quickly and that displays a "please wait" message or some suitable graphic feature,
while the real target page is being processed and delivered. In ASP 3.0 and other dynamic Web programming environments, it's common to handle this process with separate pages that implement the three execution stages shown in
Figure 3.1 The traditional separate-pages approach to providing
a "please wait" message.
ASP.NET engenders the single-page postback architecture approach. However, you can build similar features into ASP.NET applications by implementing the three pages as separate sections of a single page. The server control approach to populating elements
and attributes on the page also makes it easier to work with elements such as the
<meta> element that you use as part of the process.
Figure 3.2 shows the ASP.NET approach, as it is adopted in the example described in the following sections.
Passing Values Between Requests
Of course, what's missing from Figures 3.1 and 3.2 is how any values submitted by the user are passed from the "please wait" page to the code that creates the results. In ASP 3.0 and other dynamic Web page technologies, the
usual technique is to include a placeholder within the content attribute of the
<meta> element that gets replaced by a query string containing the values sent from the
<form> section. You can then extract these from the query string in the page or section of code that generates the results. You'll see this discussed in more detail in the section "Displaying
the "Please Wait" Message," later in this chapter.
Figure 3.2 The ASP.NET single-page approach to providing a "please
Figure 3.3 shows the initial display of a simple sample page that displays a "please wait" message while the main processing of the user's request is taking place. The page queries the
Customers table in the sample Northwind database that is provided with SQL Server. In the text box on the page, the user enters all or part of the ID of the customer he or she is looking for.
Figure 3.3 The initial page of the simple "please wait" example.
When the user clicks the Go button, the value in the text box is submitted to the server, and the page shown in
Figure 3.4 is displayed. No complex processing is required to display this page, and the total size of the content transmitted across the wire is small, so it should appear very quickly. The user knows that his or her request is being handled,
and there is no submit button for the user to play with in the meantime.
Obtaining the Sample Files
You can download this example and the other examples for this book from the Sams Web site at
http://www.samspublishing.com, or from
http://www.daveandal.net/books/6744/. You can also run many of this book's examples online at
Figure 3.4 The "please wait" message that is displayed while
processing the main page.
After a short delay (about 3 or 4 seconds, in this example), the main page, which contains the results, is returned to the user and replaces the "please wait" message. You can see in
Figure 3.5 that the main page contains a list of customers matching the partial ID value that was provided. At the bottom of the page is a New Customer link that takes the user back to the first page.
Figure 3.5 The main page, displaying the results of a search
for matching customers.
Listing 3.1 shows the relevant parts of the sample page shown in the preceding section. Notice that although you include a
<meta> element in the <head> section of the page, you don't specify any attributes for it. Instead, you give it an ID and specify that it is a server control by including the
runat="server" attribute. However, this
<meta> element will have no effect on the page or the behavior of the browser until you specify the attributes for it in the server-side code.
<!----- dynamically filled META REFRESH element ----->
<meta id="mtaRefresh" runat="server" />
<!----- form for selecting customer ----->
<form id="frmMain" Visible="False" runat="server">
Enter Customer ID:
<asp:Textbox id="txtCustomer" runat="server" />
<asp:Button id="btnSubmit" Text="Go" runat="server" />
<!----- "please wait" display ----->
<div id="divWait" Visible="False" runat="server">
<b>Searching, please wait...</b><p />
<!----- section for displaying results ----->
<div id="divResult" Visible="False" runat="server">
<b><asp:Label id="lblResult" runat="server" /></b><p />
<asp:DataGrid id="dgrResult" runat="server" /><p />
<asp:Hyperlink id="lnkNext" Text="New Customer" runat="server" />
The remainder of the page is made up of the three sections that implement the three pages shown in
Figures 3.3 through 3.5. All three pages include a
Visible="False" attribute in their container element—either the
<form> element itself for the first one or the containing
<div> element for the other two pages. So all three sections will be hidden when the page is loaded, and you can display the appropriate one by simply changing its
Visible property to True.
As you can see from the figures and code so far in this chapter, this example uses a
<meta> element in the "please wait" page to force the browser to load the main page. This much-used technique is a handy way to redirect the browser to a different page, and it is supported in almost every browser currently
in use today.
When you use the server-side Response.Redirect method in an ASP.NET (or ASP 3.0) page, the server sends two HTTP headers to the client to indicate that the browser should load a different page from the one that was
requested. The 302 Object Moved header indicates that the requested resource is now at a different location, and the
Location new-url header specifies that the resource is located at the URL denoted by new-url.
The <meta> element supports the http-equiv attribute, which is used to simulate the effects of sending specific HTTP headers to the browser. To redirect the browser to a different
URL, using a <meta> element, you can use this:
<meta http-equiv="refresh" content="[delay];url=[new-url] />
In this syntax, [delay] is the number of seconds to wait before loading the page specified in
[new-url]. All browsers will maintain the current page they are displaying until they receive the first HTTP header sent by the server for the new page. So if the processing required
for creating the new page takes a while and the server does not send any response until the processing is complete, the user will continue to see the page containing the
<meta> element (the "please wait" message). By default, ASP.NET enables response buffering, so it does not generate any output until the new page is complete and ready to send to the browser.
hope it helps