方法必须具有返回类型 [英] Method must have a return type

查看:161
本文介绍了方法必须具有返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我发送邮件的代码。唯一的问题是代码末尾标有粗体的行(''clear()'')给出了错误方法必须有返回类型。可以帮助任何人我在这方面....



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



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

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

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();
}

推荐答案

clear();

Response.Write(< script language =''javascript''> alert(''您的查询已成功发送。''); location.href (''contact_us.aspx'');< / script>);





cut clear()方法然后粘贴它在Response.Write();
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();


clear()之前是一个函数。你不能直接调用类中的函数。您只能在类中声明一个函数。可以在函数内调用函数。在编码中做一点修改。这是:

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




--Amit


这篇关于方法必须具有返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆