Reputation: 65
I have an ASP.NET web form that requests a user's user ID and domain. It then posts information to a second page that then queries AD for info on that user ID. I use session variables to store the info and all of that works perfectly. What I want is to show a message via a asp:label, wait 3 seconds and then redirect.
What I have is:
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage == null)
{
tblAccountStatus.Visible = false;
lblUserNotFound.Text = "No user ID was submitted, redirecting back to the start page.";
Response.BufferOutput = true;
System.Threading.Thread.Sleep(3000);
Server.Transfer("default.aspx");
...
This works great but the message is not displayed. All I get is a blank page for 3 seconds and then it redirects. Any ideas?
Upvotes: 0
Views: 844
Reputation: 2924
You are on the wrong way. Using Thread.Sleep in Page_load you just postpone the send of page to client. I.e., client machine sends a request to server, server wait 3 seconds (this time client receives nothing and shows a blank page) and then redirects to default.aspx.
In order to show the message for a certain time you should immediately return to the client the page with your message and execute the client-side script which waits 3 seconds and then makes a redirection.
Upvotes: 1
Reputation: 720
I am not certain but I think it is because you are sleeping and redirecting in the Page_Load method. Try to set the text in Page_Load and then in the LoadComplete event use the thread sleep and transfer.
Upvotes: 1