How to Html Page Redirect and Sent Mail

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 1382
hi
i have post the code
How to Html Page Redirect and Sent Mail


Html Page Code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type ="text/javascript">
function Tscript() {
window.location.href = "About.aspx";
return false;
}
</script>
</head>
<body>
<input id="cmd_Redirect" type ="button" name="Submit" value ="Submit" onclick ="Tscript();" />
</body>
</html>


About.aspx.cs


string strConnString = ConfigurationManager.ConnectionStrings["CntString"].ConnectionString;
string str;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Bt_Submit_Click(object sender, EventArgs e)
{

SqlConnection con = new SqlConnection(strConnString);
com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "insert into login values(@UserName,@Password,@Email)";
com.Parameters.Clear();
com.Parameters.AddWithValue("@Name", txtName.Text);
com.Parameters.AddWithValue("@Password", txtPassword.Text);
com.Parameters.AddWithValue("@Email", txtEmail.Text);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
lblmsg.Text = "Data entered successfully!!!";


try
{

string toaddress = "EmailID";
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress("FromEmailID");
msg.To.Add(new MailAddress(toaddress));
msg.Body = "Hi";
StringBuilder mailbody = new StringBuilder();
msg.Subject = " Your Account Status ";
mailbody.Append("Dear Sir Body Message");
msg.Body = mailbody.ToString();
msg.IsBodyHtml = true;
System.Net.NetworkCredential credential = new System.Net.NetworkCredential("YourEmailId", "pwd");
SmtpClient smtp = new SmtpClient();
smtp.UseDefaultCredentials = false;
smtp.Credentials = credential;
smtp.Host = "HostName";
smtp.Port = PortNo;
smtp.EnableSsl = false;
smtp.Send(msg);
}
catch (Exception ex)
{

}
}

Comments or Responses

Login to post response