本人是个菜鸟,在写上传文件,运行时发现这个问题:
编译器错误消息: CS1519: 类、结构或接口成员声明中的标记“else”无效源错误:
 行 30:    else   
行 31:     { 
行 32:      string strName = this.tb_ProductName.Text;在45行也有一个类似的错误,分别提示在 “if”、“>”和“)”中,类、结构或接口成员声明中的标记无效还有一个错误在第50行: if (type1 == "jpg" || type1 == "bmp" || type1 == "gif" || type1 == "png")
 错误提示:“命名空间并不直接包含诸如字段或方法之类的成员”相关代码如下,请各位老大帮帮忙吧,拜托了!!  protected void Btn_Submit_Click(object sender, EventArgs e)
    {
//45行:
        if ((tb_ProductName.Text == "") || (dr_ProductType.Text == "==请选择==") || (tb_kuanshi.Text == "") || (tb_xiulong.Text == "") || (tb_photo.Text == "") || (tb_mianliao.Text == "") || (tb_ling.Text == ""))
            Response.Write("<script language=javascript>alert(请添加完整各选项!');location.href='login.aspx';</script>");
    }
   else   
    { 
     string strName = this.tb_ProductName.Text;
    string  strType = this.dr_ProductType.Text;
    string  strPingPai = this.tp_PingPai.Text;
    string strKuanshi = this.tb_kuanshi .Text;
    string strXiuLong = this.tb_xiulong.Text;
    string strPhoto = this.tb_photo.Text;
    string strMianliao= this.tb_mianliao.Text;
    string strStyle = this.tb_style.Text;
    string strSeason = this.tb_season.Text;
    string tb_ling = this.tb_ling.text;
    string tb_Img1 = this.Img1_FileUpload1.FileName;//获取小图的文件的名称如:panjun.doc panjun.gif
    string type1 =tb_Img1.Substring(tb_Img1.LastIndexOf(".") + 1).ToLower(); //获取文件的类型
   int MaxLength = 1024 * 1024;//最大为1M45行:
     if (this.FileUpload1.PostedFile.ContentLength > MaxLength) //限定上传大小为1MB
            {
               Response.Write("<script>alert('上传文件的大小超过了1MB的最大容量!请压缩后再上传!')</script>");
                return;
            }
             if (type1 == "jpg" || type1 == "bmp" || type1 == "gif" || type1 == "png")
             {
                string filepath = MapPath("../upload/img/" + name);
                if (!File.Exists(filepath))
                {
                    this.FileUpload1.SaveAs(filepath);//这个是主要的完成上传的代码
                }
                else
                {
                    Response.Write("<script>alert('文件已存在,请重命名后再上传!')</script>");
                    return;
                }
                
              }
            else
            {
                Response.Write("<script>alert('你选择的文件格式不符合要求!')</script>");
                return;
            }
        }
        else
        {
            Response.Write("<script>alert('请选择一个图片文件!')</script>");
            return;
        }  }}
急呀!!在此先谢过了!!!
 

解决方案 »

  1.   

    (tb_ling.Text == "")) 后面加个 { 试试
      

  2.   

    protected void Btn_Submit_Click(object sender, EventArgs e) 
        { 
    //45行: 
            if ((tb_ProductName.Text == "") || (dr_ProductType.Text == "==请选择==") || (tb_kuanshi.Text == "") || (tb_xiulong.Text == "") || (tb_photo.Text == "") || (tb_mianliao.Text == "") || (tb_ling.Text == "")) 
                Response.Write(" <script language=javascript>alert(请添加完整各选项!');location.href='login.aspx'; </script>"); 
        } 
      else  
        { 
    你else怎么能写在这里,不错才怪了
      

  3.   

    if 后面没有{
    else 却跟在{
    这个{是 protected void Btn_Submit_Click(object sender, EventArgs e) 的
      

  4.   

     if ((tb_ProductName.Text == "") || (dr_ProductType.Text == "==请选择==") || (tb_kuanshi.Text == "") || (tb_xiulong.Text == "") || (tb_photo.Text == "") || (tb_mianliao.Text == "") || (tb_ling.Text == "")) 
                Response.Write(" <script language=javascript>alert(请添加完整各选项!');location.href='login.aspx'; </script>"); 
        } 少了个{
      

  5.   

    else在方法之外 还是老老实实 if(){}else{}这样写吧