首页上一页 1 下一页尾页 1 条记录 1/1页
编译错误 ?????请教
发表在ASP.NET图书答疑
2011-06-27
是否精华
是
否
版块置顶:
是
否
在对注册页面在浏览器上进行查看时,出现下面的错误,
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误消息: CS1061: “System.Web.UI.AttributeCollection”不包含“Page”的定义,并且找不到可接受类型为“System.Web.UI.AttributeCollection”的第一个参数的扩展方法“Page”(是否缺少 using 指令或程序集引用?)
源错误:
行 30: if (!Page.IsPostBack)
行 31: {
行 32: txtUserCode.Attributes.Page("onfoucs", "C#:calendar();");
行 33: txtUserName.Attributes.Page("onfoucs", "C#:calendar();");
行 34: txtPetName.Attributes.Page("onfoucs", "C#:calendar();");
源文件: f:\HTUmbrella\Register.aspx.cs 行: 32
附上注册页面的后台代码 请教高手们 该如何修改????
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Caching;
using System.Text.RegularExpressions;
public partial class Regist : System.Web.UI.Page
{
protected SqlConnection con = new SqlConnection(common.con);
private String UserName = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
txtUserCode.Attributes.Page("onfoucs", "C#:calendar();");
txtUserName.Attributes.Page("onfoucs", "C#:calendar();");
txtPetName.Attributes.Page("onfoucs", "C#:calendar();");
txtPasswrod.Attributes.Page("onfoucs", "C#:calendar();");
txtEmail.Attributes.Page("onfoucs", "C#:calendar();");
txtHandPhone.Attributes.Page("onfoucs", "C#:calendar();");
txtCity.Attributes.Page("onfoucs", "C#:calendar();");
}
}
protected void Button3_Click(object sender, EventArgs e)
{
//调用isNameFormar自定义方法判断用户输入的是否满足要求
if (isNameFormar())
{
//调用isName方法判断用户名是否已存在
if (isName())
{
//使用label控件显示提示信息
labIsName.Text = "用户名已存在!";
//设置label控件的颜色
labIsName.ForeColor = System.Drawing.Color.Red;
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.open('请输入正确信息!');</script>");
}
else
{
//获取用户填写的会员名
string username = txtUserName.Text;
//获取用户填写的密码并使用MD5进行加密
String password = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPasswrod.Text, "MD5");
//获取昵称
string petname = txtPetName.Text;
//获取性别
string sex = "";
//获取用户选择的性别
if (radlistSex.SelectedValue.Trim() == "男")
{
sex = "男";
}
else
{
sex = "女";
}
//获取手机号码
string hamdphone = txtHandPhone.Text;
// 获取电子邮箱
string email = txtEmail.Text;
//获取所在城市
string city = txtCity.Text;
//创建SQL语句,该语句用来添加用户的详细信息
string sqlIns = "insert into tb_Register values('" + username + "','" + password + "','" + petname + "','" + sex + "','" + hamdphone + "','" + city + "')";
//创建数据库连接
SqlConnection con = new SqlConnection("server=pc-201009111555;database=db_LX;uid=sa;pwd=halftheumbrella;");
//打开数据库连接
con.Open();
//创建sqlcommand对象
SqlCommand com = new SqlCommand(sqlIns,con);
//判断ExecutNonQuery方法返回值是否大于0,大于0表示注册成功
if (com.ExecuteNonQuery() > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.open('注册成功!');</script>");
//清空文本框中的信息
txtUserName.Text = txtPetName.Text = txtHandPhone.Text = txtEmail.Text = txtCity.Text = txtPasswrod.Text = txtPassword2.Text = txtUserCode.Text = "";
labIsName.Text = "";
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.open('请输入正确信息!');</script>");
}
}
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.open('请输入正确信息!');</script>");
}
}
protected bool isName()
{
//创建一个布尔型变量并初始化为false
bool blIsName = false;
// 创建SQL语句,该语句用来判断用户名是否存在
string sqlSel = "select count(*)form tb_Register where username='" + txtUserName.Text + "'";
//创建数据库连接
SqlConnection con = new SqlConnection("server=pc-201009111555;database=db_LX;uid=sa;pwd=halftheumbrella;");
//打开数据库连接
con.Open();
//创建sqlcommand对象
SqlCommand com = new SqlCommand(sqlSel,con);
//判断ExecuteScalar方法返回的参数是否大于0,大于表示用户名已存在
if ( Convert.ToInt32(com.ExecuteScalar()) > 0)
{
blIsName = true;
}
else
{
blIsName = false;
}
//返回布尔值变量
return blIsName;
}
protected bool isNameFormar()
{
//创建一个布尔型变量并初始化为false
bool blNameFormar=false;
//设置正则表达式
Regex re = new Regex("^\\w+$");
//使用Regex对象中的确IsMatch方法判断用户名是否满足正则表达式
if (re.IsMatch(txtUserName.Text))
{
//设置布尔变量为true
blNameFormar = true;
//设置label控件的颜色
labIsName.ForeColor=System.Drawing.Color.Black;
}
else
{
labIsName.ForeColor=System.Drawing.Color.Red;
blNameFormar=false;
}
//返回布尔型变量
return blNameFormar;
}
protected void txtUserName_Textchanged(object sender, EventArgs e)
{
//判断用户名是否为空
if (txtUserName.Text == "")
{
//使用Label控件给出提示
labIsName.Text = "用户名不能为空";
//设置Label控件的颜色
labIsName.ForeColor = System.Drawing.Color.Red;
}
else
{
//调用isNameFormar自定义方法判断用户名是否满足格式要求
if (isNameFormar())
{
//调用isName自定义方法判断用户名是否注册
if (isName())
{
labIsName.Text = "用户名已存在!";
labIsName.ForeColor = System.Drawing.Color.Red;
}
else
{
labIsName.Text = "可以注册!";
labIsName.ForeColor = System.Drawing.Color.Blue;
}
}
else
{
labIsName.Text = "";
}
}
}
}
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误消息: CS1061: “System.Web.UI.AttributeCollection”不包含“Page”的定义,并且找不到可接受类型为“System.Web.UI.AttributeCollection”的第一个参数的扩展方法“Page”(是否缺少 using 指令或程序集引用?)
源错误:
行 30: if (!Page.IsPostBack)
行 31: {
行 32: txtUserCode.Attributes.Page("onfoucs", "C#:calendar();");
行 33: txtUserName.Attributes.Page("onfoucs", "C#:calendar();");
行 34: txtPetName.Attributes.Page("onfoucs", "C#:calendar();");
源文件: f:\HTUmbrella\Register.aspx.cs 行: 32
附上注册页面的后台代码 请教高手们 该如何修改????
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Caching;
using System.Text.RegularExpressions;
public partial class Regist : System.Web.UI.Page
{
protected SqlConnection con = new SqlConnection(common.con);
private String UserName = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
txtUserCode.Attributes.Page("onfoucs", "C#:calendar();");
txtUserName.Attributes.Page("onfoucs", "C#:calendar();");
txtPetName.Attributes.Page("onfoucs", "C#:calendar();");
txtPasswrod.Attributes.Page("onfoucs", "C#:calendar();");
txtEmail.Attributes.Page("onfoucs", "C#:calendar();");
txtHandPhone.Attributes.Page("onfoucs", "C#:calendar();");
txtCity.Attributes.Page("onfoucs", "C#:calendar();");
}
}
protected void Button3_Click(object sender, EventArgs e)
{
//调用isNameFormar自定义方法判断用户输入的是否满足要求
if (isNameFormar())
{
//调用isName方法判断用户名是否已存在
if (isName())
{
//使用label控件显示提示信息
labIsName.Text = "用户名已存在!";
//设置label控件的颜色
labIsName.ForeColor = System.Drawing.Color.Red;
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.open('请输入正确信息!');</script>");
}
else
{
//获取用户填写的会员名
string username = txtUserName.Text;
//获取用户填写的密码并使用MD5进行加密
String password = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPasswrod.Text, "MD5");
//获取昵称
string petname = txtPetName.Text;
//获取性别
string sex = "";
//获取用户选择的性别
if (radlistSex.SelectedValue.Trim() == "男")
{
sex = "男";
}
else
{
sex = "女";
}
//获取手机号码
string hamdphone = txtHandPhone.Text;
// 获取电子邮箱
string email = txtEmail.Text;
//获取所在城市
string city = txtCity.Text;
//创建SQL语句,该语句用来添加用户的详细信息
string sqlIns = "insert into tb_Register values('" + username + "','" + password + "','" + petname + "','" + sex + "','" + hamdphone + "','" + city + "')";
//创建数据库连接
SqlConnection con = new SqlConnection("server=pc-201009111555;database=db_LX;uid=sa;pwd=halftheumbrella;");
//打开数据库连接
con.Open();
//创建sqlcommand对象
SqlCommand com = new SqlCommand(sqlIns,con);
//判断ExecutNonQuery方法返回值是否大于0,大于0表示注册成功
if (com.ExecuteNonQuery() > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.open('注册成功!');</script>");
//清空文本框中的信息
txtUserName.Text = txtPetName.Text = txtHandPhone.Text = txtEmail.Text = txtCity.Text = txtPasswrod.Text = txtPassword2.Text = txtUserCode.Text = "";
labIsName.Text = "";
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.open('请输入正确信息!');</script>");
}
}
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.open('请输入正确信息!');</script>");
}
}
protected bool isName()
{
//创建一个布尔型变量并初始化为false
bool blIsName = false;
// 创建SQL语句,该语句用来判断用户名是否存在
string sqlSel = "select count(*)form tb_Register where username='" + txtUserName.Text + "'";
//创建数据库连接
SqlConnection con = new SqlConnection("server=pc-201009111555;database=db_LX;uid=sa;pwd=halftheumbrella;");
//打开数据库连接
con.Open();
//创建sqlcommand对象
SqlCommand com = new SqlCommand(sqlSel,con);
//判断ExecuteScalar方法返回的参数是否大于0,大于表示用户名已存在
if ( Convert.ToInt32(com.ExecuteScalar()) > 0)
{
blIsName = true;
}
else
{
blIsName = false;
}
//返回布尔值变量
return blIsName;
}
protected bool isNameFormar()
{
//创建一个布尔型变量并初始化为false
bool blNameFormar=false;
//设置正则表达式
Regex re = new Regex("^\\w+$");
//使用Regex对象中的确IsMatch方法判断用户名是否满足正则表达式
if (re.IsMatch(txtUserName.Text))
{
//设置布尔变量为true
blNameFormar = true;
//设置label控件的颜色
labIsName.ForeColor=System.Drawing.Color.Black;
}
else
{
labIsName.ForeColor=System.Drawing.Color.Red;
blNameFormar=false;
}
//返回布尔型变量
return blNameFormar;
}
protected void txtUserName_Textchanged(object sender, EventArgs e)
{
//判断用户名是否为空
if (txtUserName.Text == "")
{
//使用Label控件给出提示
labIsName.Text = "用户名不能为空";
//设置Label控件的颜色
labIsName.ForeColor = System.Drawing.Color.Red;
}
else
{
//调用isNameFormar自定义方法判断用户名是否满足格式要求
if (isNameFormar())
{
//调用isName自定义方法判断用户名是否注册
if (isName())
{
labIsName.Text = "用户名已存在!";
labIsName.ForeColor = System.Drawing.Color.Red;
}
else
{
labIsName.Text = "可以注册!";
labIsName.ForeColor = System.Drawing.Color.Blue;
}
}
else
{
labIsName.Text = "";
}
}
}
}