joe_pool_is Posted August 16, 2005 Posted August 16, 2005 Does anyone know how to make the form sleep in ASP.NET? I want the page to sleep for a bit before redirecting to another page. Regards, Joe Quote Avoid Sears Home Improvement
kahlua001 Posted August 16, 2005 Posted August 16, 2005 i believe its system.thread.sleep(x) where x is milliseconds Quote
joe_pool_is Posted August 16, 2005 Author Posted August 16, 2005 i believe its system.thread.sleep(x) where x is millisecondsDoesn't work. I got: Compiler Error Message: CS0246: The type or namespace name 'system' could not be found (are you missing a using directive or an assembly reference?) Source Error:[/b]Line 132: Line 133: public void GoHome(object sender, System.EventArgs e) { [color=red]Line 134: system.thread.sleep(20000);[/color] Line 135: Response.Redirect([url="http://www.google.com/"]http://www.google.com/[/url]); Line 136: } Quote Avoid Sears Home Improvement
kahlua001 Posted August 16, 2005 Posted August 16, 2005 sorry, its System.Threading.Thread.Sleep(x) Quote
Administrators PlausiblyDamp Posted August 16, 2005 Administrators Posted August 16, 2005 Asp.net doesn't work that way - there is no point making the server sleep for a while as that will just delay the page being sent to the client (which will then redirect immediately anyway). You would either need to use a Meta Refresh or possibly a bit of client side javascript. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
joe_pool_is Posted August 16, 2005 Author Posted August 16, 2005 sorry, its System.Threading.Thread.Sleep(x)Looks like this makes everything sort of freeze up for a bit, which is not what we are trying to do. A little background: This is for a form mailer with two panel controls: Panel1 is visible and has the standard "email form" features; Panel2 is hidden and displays a confirmation to the visitor after the message has been sent. We want the website to show Panel2 after the message has been submitted, then return to our homepage after x milliseconds ...unless the visitor decides to browse elsewhere, of course. Sleep() just seems to halt everything; Panel2 never shows. Am I using it incorrectly, or is there another function that I want for this? I would use the JavaScript setTimeout() function, but my code does NOT like this. Quote Avoid Sears Home Improvement
kahlua001 Posted August 17, 2005 Posted August 17, 2005 Yes, then in this case thread.sleep is not what you want. JS will work, or use a meta tag like.. <meta http-equiv="refresh" content="10;url=http://www.google.com"> Quote
joe_pool_is Posted August 17, 2005 Author Posted August 17, 2005 kahlua001 and PlausiblyDamp: I have one form with two panels. How would I get the "meta tag" or "JS" to be idle when one panel is active, then perform its job when the other panel becomes active? Yes, I could use two separate webpages, but this admits defeat! Quote Avoid Sears Home Improvement
kahlua001 Posted August 17, 2005 Posted August 17, 2005 So when one panel becomes active, why cant you use the setTimeout function in JS to wait and then redirect? Was it not working for you before? Show us your code. Quote
joe_pool_is Posted August 17, 2005 Author Posted August 17, 2005 So when one panel becomes active' date=' why cant you use the setTimeout function in JS to wait and then redirect? Was it not working for you before? Show us your code.[/quote']The problem is getting JS and ASP to talk to one another. Is it really possible? I had to greatly simplify my code, but here it is:<%@ Page Language="c#" %> <%@ import Namespace="System.Text" %> <%@ import Namespace="System.IO" %> <%@ import Namespace="System.Web.Mail" %> <script runat="server"> public void OnClickSubmit (object sender, System.EventArgs e) { string strUsername = "JonDoe"; // no, this is not my username string strPassword = "123xxx"; // no, this is not my password SmtpMail.SmtpServer = "smtp.mail.yahoo.com"; // Yahoo!'s $19/year service MailMessage mail = new MailMessage(); mail.Subject = "New Email From Website"; mail.From = "\"" + Request.Form["txtName"] + "\" <" + Request.Form["txtEmail"] + ">"; mail.To = strMyEmailAddress; mail.Body = Request.Form["txtMessage"]; mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", strUsername); mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", strPassword); SmtpMail.Send(mail); lblResponse.Text = "<h3><center>Thank You!</center></h3>Your message has successfully been sent.<hr>"; MainPanel.Visible = false; DonePanel.Visible = true; } </script> <html> <head><title>Mail Form</title></head> <body> <asp:panel id="MainPanel" runat="server" Width="100%"> <form id="Form1" method="post" runat="server"> <table width="100%"><tbody> <tr><td align="middle" colspan="2"><h3>Email Form</h3></td></tr> <tr> <td align="right"><b>Name:</b></td> <td align="left"><asp:textbox id="txtName" runat="server" /></td> </tr> <tr> <td align="right"><b>Email:</b></td> <td align="left"><asp:textbox id="txtEmail" runat="server" /></td> </tr> <tr> <td align="middle" colspan="2"><b>Message:</b><br /> <asp:textbox id="txtMessage" runat="server" Rows="10" Columns="60" TextMode="MultiLine" /><br /> <asp:button id="submit" onclick="OnClickSubmit" runat="server" Text="Send" /> </td> </tr> </tbody></table> </form> <center>Click <a href="javascript:history.go(-1)">here</a> to go back. </asp:panel> <asp:panel id="DonePanel" runat="server" Width="100%" Visible="False"> <form id="Form2" runat="server"> <asp:Literal id="lblResponse" runat="server"></asp:Literal> </form> <center>Click <a href="javascript:history.go(-2)">here</a> to go back.</center> </asp:panel> </body> </html> Quote Avoid Sears Home Improvement
kahlua001 Posted August 17, 2005 Posted August 17, 2005 When you enable the second panel, you write some js to the page like.. <Script language="javascript"> setTimeout("window.location = 'http://www.google.com'",5000); </script> Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.