请高手帮忙

wumukang 2012-03-22 01:11:23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class w1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click (object sender, EventArgs e)
{

if (this.txtLoginId.Text.Trim().Length == 0)
{
this.lblMessage.Text = "请输入用户名!";
return;
}
if (this.txtLoginId.Text.Trim().Length == 0)
{
this.lblMessage.Text = "请输入密码!";
return;
}
if (this.txtLoginId.Text.Trim() == "abc" &&

this.txtLoginId.Text.Trim() == "123")
{

User user = new User ();
user.Username = txtLoginId.Text;
user.PassWord = txtLoginId.Text;
Session["User"] = user;
Response.Cookies["LoginTime"].Value = DateTime.Now.ToString();
Response.Redirect("Welcome.aspx");
}
else
{
this.lblMessage.Text = "用户名/密码错误!";
}
}

}



错误 1 “User”不包含“Username”的定义,并且找不到可接受类型为“User”的第一个参数的扩展方法“Username”(是否缺少 using 指令或程序集引用?)

错误 2 “User”不包含“PassWord”的定义,并且找不到可接受类型为“User”的第一个参数的扩展方法“PassWord”(是否缺少 using 指令或程序集引用?)
...全文
149 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
苦逼孩子 2012-03-22
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Page.user; //这里必须声明user因为他是在page类里面的


//如果引用这种那么写法是
Page page=new Page();
page.user.username="赋值";
page.user.userpaswrod="赋值";

//注意这种写法在你的page类的构造方法里面需要这样写:
public page()
{
User user=new User(); //实例化user对象;
}



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using USER //第二种写法


//如果引用这种那么写法是
user user=new user();
user.name="";
user.password="";

//注意这种写法在你的page类的构造方法里面需要这样写:

wumukang 2012-03-22
  • 打赏
  • 举报
回复
成功啦!太感谢啦
#blackheart 2012-03-22
  • 打赏
  • 举报
回复
你的User类名字和Page的User属性冲突了,,,,改下你的自定义类User名字,或者用系统提供的 System.ServiceModel.Security.UserNamePasswordClientCredential
EnForGrass 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 chinajiyong 的回复:]

引用 13 楼 chinajiyong 的回复:

引用 12 楼 wumukang 的回复:

引用 11 楼 chinajiyong 的回复:

引用 5 楼 wumukang 的回复:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

///……
[/Quote]

把User类改成


public class User
{
private string username;
private string password;
public User()
{
}
public string Username
{
get { return username; }
set { username = value; }
}
public string PassWord
{
get { return password; }
set { password = value; }
}
}


页面引用

protected void Page_Load(object sender, EventArgs e)
{
User user = new User();
user.Username = "James";
user.PassWord = "123";
}
EnForGrass 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 chinajiyong 的回复:]

引用 12 楼 wumukang 的回复:

引用 11 楼 chinajiyong 的回复:

引用 5 楼 wumukang 的回复:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///User 的摘要说明
/……
[/Quote]
改一下

protected void Page_Load(object sender, EventArgs e)
{
User user = new User();
user.Username = "James";
user.PassWord = "123";
}
EnForGrass 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 wumukang 的回复:]

引用 11 楼 chinajiyong 的回复:

引用 5 楼 wumukang 的回复:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///User 的摘要说明
/// </summary>
public cla……
[/Quote]
把User类改成

public class User
{
private string username;
private string password;
public UserClass()
{
}
public string Username
{
get { return username; }
set { username = value; }
}
public string PassWord
{
get { return password; }
set { password = value; }
}
}

在你页面可以直接引用

protected void Page_Load(object sender, EventArgs e)
{
UserClass user = new UserClass();
user.Username = "James";
user.PassWord = "123";
}

wumukang 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 chinajiyong 的回复:]

引用 5 楼 wumukang 的回复:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///User 的摘要说明
/// </summary>
public class User
{
public User() {}……
[/Quote]

刚刚学不会啊,怎么办呢?
EnForGrass 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wumukang 的回复:]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///User 的摘要说明
/// </summary>
public class User
{
public User() {}




……
[/Quote]
你怎么User还包含user呢?
wumukang 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 chinajiyong 的回复:]

引用 8 楼 wumukang 的回复:

怎么办啊,你写下

User是个类还是个类库中的,如果是类的话,把直接可以用。如果是类库的话,在你的web项目的引用,右击选择引用,添加包含User的类库,然后在调用User的页面using User的命名空间,就可以了
[/Quote]

是类的
EnForGrass 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wumukang 的回复:]

怎么办啊,你写下
[/Quote]
User是个类还是个类库中的,如果是类的话,把直接可以用。如果是类库的话,在你的web项目的引用,右击选择引用,添加包含User的类库,然后在调用User的页面using User的命名空间,就可以了
wumukang 2012-03-22
  • 打赏
  • 举报
回复
怎么办啊,你写下
EnForGrass 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wumukang 的回复:]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///User 的摘要说明
/// </summary>
public class User
{
public User() {}




……
[/Quote]
引用没有
wumukang 2012-03-22
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///User 的摘要说明
/// </summary>
public class User
{
public User() {}




public class user
{
private string username;
private string password;
public user()
{
}
public string Username
{
get { return username; }
set { username = value; }
}
public string PassWord
{
get { return password; }
set { password = value; }
}
}
}

wumukang 2012-03-22
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///User 的摘要说明
/// </summary>
public class User
{
public User() {}




public class user
{
private string username;
private string password;
public user()
{
}
public string Username
{
get { return username; }
set { username = value; }
}
public string PassWord
{
get { return password; }
set { password = value; }
}
}
}

这是类啊
happytonice 2012-03-22
  • 打赏
  • 举报
回复
1.换个类名
2.给类加上名空间
3.类中添好public string Password { get; set; }
public string UserName { get; set; }
}
4.在引用的地方加入using 引用类的名空间
5.实体化使用
#blackheart 2012-03-22
  • 打赏
  • 举报
回复
Page类有一个User属性了。
public IPrincipal User { get; }

如果你用的User是你自定义的
1:你加上命名空间,用全名写。
2:你把自定义的User改名吧。
3:如下的类是系统类库的,或许你可以用
namespace System.ServiceModel.Security
{
// 摘要:
// 表示基于用户名和密码的客户端凭据。
public sealed class UserNamePasswordClientCredential
{
// 摘要:
// 获取或设置密码。
//
// 返回结果:
// 密码。
public string Password { get; set; }
//
// 摘要:
// 获取或设置用户名。
//
// 返回结果:
// 用户名。
public string UserName { get; set; }
}
}
EnForGrass 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 wumukang 的回复:]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class w1 : System.Web.UI.Page
{
……
[/Quote]
请加上User的命名空间
bdmh 2012-03-22
  • 打赏
  • 举报
回复
你的User 类在哪呢

62,039

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧