Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
i believe its system.thread.sleep(x)

 

where x is milliseconds

Doesn'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: }

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
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.

Posted
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>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...