how to cross redirect a form to .aspx page and mail

Posted by Parthibansk under ASP.NET on 3/20/2013 | Points: 10 | Views : 1049 | Status : [Member] | Replies : 1
i developed a contact us form in asp.net with mailing and data store..

now i have been given normal html form..when users clik on button event of html form it has to redirect to my contact.aspx page and mailing..
how this could be achieved..




Responses

Posted by: Jayakumars on: 3/20/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this code



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)
{

}
}

Mark as Answer if its helpful to you

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response