所以我做了一个登录系统,现在我不允许用户更新他们的信息。我认为这段代码可以工作,但它没有,这里是:
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。这似乎是一个简单的修复,但我有点迷路了。因此,总结主要问题是如何将用户信息更新为用户在文本框中输入的新文本。