Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Below is my code for sending mail.the only problem is that the line marked bold at the end of the code('clear()')gives me the error "Method must have return type".Can anybody help me in this regard....

*************************************************************

C#
public partial class contact_us : System.Web.UI.Page
{
    protected void Page_Load(object sender, System.EventArgs e)
	{
	}
    public void clear()
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
    }
    
    protected void image_Click(object sender, ImageClickEventArgs e)
    {
        
        //(1) Create the MailMessage instance
        

            MailMessage mail = new MailMessage();
            mail.To.Add("xyz@gmail.com");
            mail.From = new MailAddress(TextBox2.Text);
            mail.Subject = "Inquiry regarding Umang Party Plot";
            mail.Body =  TextBox4.Text;
            mail.IsBodyHtml = true;

            //(3) Create the SmtpClient object
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";

            //Or Your SMTP Server Address
            smtp.Credentials = new System.Net.NetworkCredential("xyz@gmail.com", "12345");

            //Or your Smtp Email ID and Password
            smtp.EnableSsl = true;
            smtp.Send(mail);
        
       
        Response.Write("<script language='javascript'>alert('Your Inquiry has been Successfully send.');location.href('contact_us.aspx');</script>");
     
    }
  clear();
}
Posted
Updated 23-Dec-12 20:01pm
v3
Comments
[no name] 24-Dec-12 2:03am    
I assume that you are aware with that Void returns nothing..

clear();
Response.Write("<script language='javascript'>alert('Your Inquiry has been Successfully send.');location.href('contact_us.aspx');</script>");


cut clear() method then paste it before Response.Write();
 
Share this answer
 
clear() is a function here. You cannot call the function inside the class directly. You can only declare a function in the class. A function can be called inside a function. Do a little modificaiton in your coding. Here it is:
C#
public partial class contact_us : System.Web.UI.Page
{
    protected void Page_Load(object sender, System.EventArgs e)
	{
	}
    public void clear()
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
    }
    
    protected void image_Click(object sender, ImageClickEventArgs e)
    {
        
        //(1) Create the MailMessage instance
        
 
            MailMessage mail = new MailMessage();
            mail.To.Add("xyz@gmail.com");
            mail.From = new MailAddress(TextBox2.Text);
            mail.Subject = "Inquiry regarding Umang Party Plot";
            mail.Body =  TextBox4.Text;
            mail.IsBodyHtml = true;
 
            //(3) Create the SmtpClient object
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
 
            //Or Your SMTP Server Address
            smtp.Credentials = new System.Net.NetworkCredential("xyz@gmail.com", "12345");
 
            //Or your Smtp Email ID and Password
            smtp.EnableSsl = true;
            smtp.Send(mail);
        
       
        Response.Write("<script language="'javascript'">alert('Your Inquiry has been Successfully send.');location.href('contact_us.aspx');</script>");
        //Put it inside the function.
        clear();
    }
}



--Amit
 
Share this answer
 
Comments
Thanks7872 24-Dec-12 2:13am    
ok.the problem got solved...thanks for that...now the problem is every time i reload the page,the mail is being sent....how to overcome this issue?as i am new to c#?
_Amy 24-Dec-12 2:19am    
Yes. I know, this issue is there from the beginning in Asp.Net. After pressing F5 it'll ask you to resend the data. And if you'll click resend, then the mail will be sent. No need to worry about that issue. Actually it's not an issue.

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