Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello friends
I am Sarfaraz. I am developing a small website in asp.net. I have created a master page and at the bottom of that master page i have a feedback form which users can fill and send it on my email.
Now i have another form placeorder.aspx where i am supposed to have an order form so that users can fill that and send the order form on my email id. But when i run the website I am able to send email from the master page form but not from the placeorder form.
Is it that i can send email only at one place on a single form.If no then how to implement it.
Please help
Thank you
Posted
Comments
Deflinek 16-Apr-14 15:00pm    
Please clarify what do you mean you are not able to send email. Do you have any errors? Is the event handler called at all?
sarfarazbhat 16-Apr-14 23:04pm    
Actually i have a master page with a feedback form at the bottom.
I have also a page named placeorder where i am also having an order form on that page. Since this placeorder page has now two forms one that of master page at the bottom in the footer and another form of its own.
When i am deleting master page form i am able to send email from placeorder form. But not otherwise.
The code is as under both codes are working correctly but only if i remove form from master page.
Placeorder email button:

protected void btnsendorder_Click(object sender, EventArgs e)
{
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string msg = string.Empty;
try
{
MailAddress fromAddress = new MailAddress(txtemail.Text);
message.From = fromAddress;
message.To.Add("mymail@gmail.com");

message.Subject = txtname.Text;
message.IsBodyHtml = true;
message.Body = "" + txtname.Text + "<br/>" + txtaddress.Text + "<br/>" + txtcontact.Text + "" + "<br/>" + txtorderdetails.Text;
smtpClient.Host = "smtp.gmail.com"; // We use gmail as our smtp client
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential("mymail@gmail.com", "12345");

smtpClient.Send(message);
msg = "Successful<BR>";

Response.Redirect("~/Default.aspx");
clear();
}
catch (Exception ex)
{
msg = ex.Message;
}
}

Masterpage form email:

protected void btnsend_Click(object sender, EventArgs e)
{


MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string msg = string.Empty;
try
{
MailAddress fromAddress = new MailAddress(txtemail.Text);
message.From = fromAddress;
message.To.Add("mymail@gmail.com");

message.Subject = txtname.Text;
message.IsBodyHtml = true;
message.Body = "" + txtname.Text + "<br/>" + txtemail.Text + "<br/>" + txtphone.Text + "" + "<br/>" + txtmessage.Text;
smtpClient.Host = "smtp.gmail.com"; // We use gmail as our smtp client
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential("mymail@gmail.com", "12345");

smtpClient.Send(message);
msg = "Successful<BR>";

Response.Redirect("~/Default.aspx");
clear();
}
catch (Exception ex)
{
msg = ex.Message;
}




}
Deflinek 17-Apr-14 8:34am    
Thanks for posting your event handlers. One thing to ensure is that there is only one
<Form runat="server"> element. It should be on masterpage surrounding all content placeholders and any other form elements on master page (textboxes, buttons,...)
If you had two form elements with runat="server" then that is the problem here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900