【问题标题】:Update a users profile information using simple textboxs使用简单的文本框更新用户个人资料信息
【发布时间】:2013-06-18 23:16:09
【问题描述】:

所以我做了一个登录系统,现在我不想让用户更新他们的信息。我认为这段代码可以工作,但它没有,这里是:

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

    MembershipUser usr = Membership.GetUser();
    if (usr.IsApproved == false)
    {
        Response.Redirect("~/Login.aspx");
    }
    var p = Profile.GetProfile(usr.UserName);
    /* Displays all current profile information once the page loads */
    FirstName.Text = p.fName;
    LastName.Text = p.lName;
    Address.Text = p.Address;
    Email.Text = usr.Email;
    Company.Text = p.Company;
}
/* Simple button to take you to the home screen */
protected void Button2_Click(object sender, EventArgs e)
{
    Response.Redirect("~/default.aspx");
}

protected void UpdateButton_Click(object sender, EventArgs e)
{
    MembershipUser usr = Membership.GetUser();
    var p = Profile.GetProfile(usr.UserName);
    /* Update all information that the user has changed */
    p.fName = FirstName.Text;
    p.Save();
    p.lName = LastName.Text;
    p.Save();
    p.Address = Address.Text;
    p.Save();
    usr.Email = Email.Text;
    Membership.UpdateUser(usr);
    p.Company = Company.Text;
    p.Save();
    Success.Text = "User Information has been updated";
    /* Redisplaying the updated user information */
    FirstName.Text = p.fName;
    LastName.Text = p.lName;
    Address.Text = p.Address;
    Email.Text = usr.Email;
    Company.Text = p.Company;
  }
}

问题似乎是,无论我将文本框中的文本更改为什么,都不会改变文本框中最初的内容。因此,如果最初用户的名字是 Bob,我在点击更新按钮时将其更改为 Robert,它不会将其更改为 Robert。这似乎是一个简单的修复,但我有点迷路了。所以总结一下主要问题是如何将用户信息更新为用户在文本框中输入的新文本。

【问题讨论】:

  • 文本框用的是什么类?我看了看,但找不到文本框的 Web.UI 等效项。另外,p是什么类? (编译器可能能够推断出来,但这个人不能大声笑)

标签: c# asp.net textbox profile


【解决方案1】:

在页面加载时输入!Ispostback

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
    MembershipUser usr = Membership.GetUser();
    if (usr.IsApproved == false)
    {
        Response.Redirect("~/Login.aspx");
    }
    var p = Profile.GetProfile(usr.UserName);
    /* Displays all current profile information once the page loads */
    FirstName.Text = p.fName;
    LastName.Text = p.lName;
    Address.Text = p.Address;
      Email.Text = usr.Email;
      Company.Text = p.Company;
   }
}

如果你不使用它,总是当信息进入服务器时你会得到 olds 值。

干杯。

【讨论】:

  • 啊新我错过了一些简单的东西!非常感谢!
猜你喜欢
  • 2020-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-06
  • 2022-10-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多