我复制了一个旧表单,并使用不同的字段创建了这个新表单,现在收到以下错误消息。
\ www \ assets \ root \ forms \ revenueanalysis.aspx.cs(50,13):错误CS0103:当前上下文中不存在名称“EmailCollections”
\ www \ assets \ root \ forms \ revenueanalysis.aspx.cs(61,18):错误CS0103:当前上下文中不存在名称“Utility”
\ www \ assets \ root \ forms \ revenueanalysis.aspx.cs(74,18):错误CS0103:当前上下文中不存在名称“Utility”
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Net.Mail;
using System.Web.Mail;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.IO;
using System.Linq;
public partial class revenueanalysis : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (IsFormValid())
{
string name = string.Empty;
string emailAddress = string.Empty;
string emailAddress2 = string.Empty;
string phone = string.Empty;
string title = string.Empty;
string company = string.Empty;
string comment = string.Empty;
string specialties = string.Empty;
string cases = string.Empty;
name = tbName.Text;
emailAddress = tbEmail.Text;
emailAddress2 = tbEmail2.Text;
phone = tbPhone.Text;
title = tbTitle.Text;
company = tbCompany.Text;
comment = tbComment.Text;
specialties = tbSpecialties.Text;
cases = tbCases.Text;
EmailCollections.SendNewrevenueanalysisFormEmail(name, emailAddress, emailAddress2, phone, title, company, comment, specialties, cases, this);
}
}
private bool IsFormValid()
{
bool isvalid = true;
if (string.IsNullOrEmpty(tbName.Text)) { isvalid = false; lblName.CssClass = "error"; } else { lblName.CssClass = ""; }
if (string.IsNullOrEmpty(tbEmail.Text)) { isvalid = false; lblEmail.CssClass = "error"; }
else
{
if (!Utility.IsEmailValid(tbEmail.Text))
{
isvalid = false;
lblEmail.CssClass = "error";
}
else
{
lblEmail.CssClass = "";
}
}
if (string.IsNullOrEmpty(tbEmail2.Text)) { isvalid = false; lblEmail.CssClass = "error"; }
else
{
if (!Utility.IsEmailValid(tbEmail2.Text))
{
isvalid = false;
lblEmail.CssClass = "error";
}
else
{
lblEmail.CssClass = "";
}
}
if (string.IsNullOrEmpty(tbPhone.Text)) { isvalid = false; lblPhone.CssClass = "error"; } else { tbPhone.CssClass = ""; }
if (string.IsNullOrEmpty(tbTitle.Text)) { isvalid = false; lblTitle.CssClass = "error"; } else { tbTitle.CssClass = ""; }
if (string.IsNullOrEmpty(tbCompany.Text)) { isvalid = false; lblCompany.CssClass = "error"; } else { tbCompany.CssClass = ""; }
if (string.IsNullOrEmpty(tbComment.Text)) { isvalid = false; lblComment.CssClass = "error"; } else { tbComment.CssClass = ""; }
return isvalid;
}
}
- - - - - - - - 更新 这是我复制过的代码,看起来所有'using'语句都是一样的。这种形式正常运作。
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Net.Mail;
using System.Web.Mail;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.IO;
using System.Linq;
public partial class RequestProposal : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (IsFormValid())
{
string name = string.Empty;
string emailAddress = string.Empty;
string phone = string.Empty;
string message = string.Empty;
string cases = string.Empty;
string specialties = string.Empty;
string nOperatingR = string.Empty;
string nProcedureR = string.Empty;
string state = string.Empty;
name = tbName.Text;
emailAddress = tbEmail.Text;
phone = tbPhone.Text;
message = tbComment.Text;
cases = tbCases.Text;
specialties = tbSpecialties.Text;
nOperatingR = tbOperatingR.Text;
nProcedureR = tbProcedureR.Text;
state = tbState.Text;
EmailCollections.SendNewRequestProposalFormEmail(name, emailAddress, phone, message, cases, specialties, nOperatingR, nProcedureR, state, this);
}
}
private bool IsFormValid()
{
bool isvalid = true;
if (string.IsNullOrEmpty(tbName.Text)) { isvalid = false; lblName.CssClass = "error"; } else { lblName.CssClass = ""; }
if (string.IsNullOrEmpty(tbEmail.Text)) { isvalid = false; lblEmail.CssClass = "error"; }
else
{
if (!Utility.IsEmailValid(tbEmail.Text))
{
isvalid = false;
lblEmail.CssClass = "error";
}
else
{
lblEmail.CssClass = "";
}
}
if (string.IsNullOrEmpty(tbComment.Text)) { isvalid = false; lblComment.CssClass = "error"; } else { tbComment.CssClass = ""; }
return isvalid;
}
}
答案 0 :(得分:0)
您正试图在btnSubmit_Click方法的末尾访问“EmailCollections”对象:
EmailCollections.SendNewrevenueanalysisFormEmail(name, emailAddress, emailAddress2, phone, title, company, comment, specialties, cases, this);
您还尝试在多个位置访问“Utility”对象:
if (!Utility.IsEmailValid(tbEmail.Text))
您收到的错误是因为系统不知道在哪里找到这些对象。是否有可能当您复制旧的for时,您丢失了顶部指向缺少对象的命名空间的一些“using”语句?如果你仍然有旧的副本,我建议检查“使用”语句,并包括那些包含缺少的对象定义的语句。