我在default.aspx.cs文件里写了这个函数,结果报错说上下文不存在UserName和Password,我用的是asp.net和C#protected string getUserName(TextBox UserName)
{
return UserName.Text;
}
protected string getPassword(TextBox Password)
{
return Password.Text;
}
protected void LoginButton_Click(object sender, EventArgs e)
{
BookDAL bookdal = new BookDAL();
string username = getUserName(UserName);
string password = getPassword(Password);
bool result = bookdal.UserLogin(username, password);
if (result)
{
Response.Redirect("default.aspx");
}
else
{
Response.Redirect("login.aspx");
}
}请高手指教啊~~~~~~~~~~~~~在线等答案!
解决方案 »
- asp.net DateTime.Now格式问题
- 求随机生成ID的代码
- 请问一框架设计问题,对于有三层框架上左右的页面在左侧放有导航菜单,右侧为用户登录,现在我有这样一个问题,就是不用登录就能进行左侧
- asp.net部署在windows2003server出现乱码
- 自定义控件:如何让背景图片只下载一次.
- 简单问题,急,在线等!
- sql2000+asp.net(vb)如何直接在表中累计一个字段
- 如何让数据库中的所有数据归零?
- asp.net 中在webconfig中添加参数控制页面的按钮显示与隐藏
- IsolationLevel问题
- 搜索框制作
- VS2010创建的网站,没有release选项???
{
get{return UserName.Text;}
set {UserName.Text=value;}
}
textbox的ID为UserName
但是没有传进去textbox的参数,函数里面不是找不到UserName吗?
protected string username
{
get{return UserName.Text;}
set {UserName.Text=value;}
}
{
BookDAL bookdal = new BookDAL();
string username = UserName.Text;
string password = Password.Text;
bool result = bookdal.UserLogin(username, password);
if (result)
{
Response.Redirect("default.aspx");
}
else
{
Response.Redirect("login.aspx");
}
}
或者:
-----------------------------------------
先定义二个属性 :
protected string username
{
get{return UserName.Text;}}protected string password
{
get{return UserName.Text;}}按钮事件如下:
protected void LoginButton_Click(object sender, EventArgs e)
{
BookDAL bookdal = new BookDAL();
string username = username;
string password = password;
bool result = bookdal.UserLogin(username, password);
if (result)
{
Response.Redirect("default.aspx");
}
else
{
Response.Redirect("login.aspx");
}
}
用户名的ID定义为:UserName;
密码的ID定义为:Password
因为我上面的那个提交按钮事件里就直接用了UserName和Password,结果它报错,说“上下文上下文找不到UserName和Password”
????这是为什么呢?
{
BookDAL bookdal = new BookDAL();
// string username = getUserName(UserName);
// string password = getPassword(Password);
//string username = Username;
// string password = PassWord;
bool result = bookdal.UserLogin(Login1.UserName, Login1.Password);
if (result)
{
Response.Redirect("default.aspx");
}
else
{
Response.Redirect("login.aspx");
}
}后来我这么做了,原来用Login1.UserName可以传参进去,但是我Login1.UserName是什么类型的啊?我以为它是TextBox类型的……但是传参的时候,参数类型应该是string才对啊……