2013-06-18 36 views
0

因此,我創建了一個登錄系統,現在我不想讓用戶更新他們的信息。我認爲這個代碼的工作,但事與願違,那就是:使用簡單的文本框更新用戶配置文件信息

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。這似乎是一個簡單的修復,但我有點失落。所以總結一下,主要問題是如何將用戶信息更新爲用戶在文本框中輸入的新文本。

+0

你在文本框中使用了什麼類?我看了一下,但找不到Web.UI等價的文本框。另外,p是什麼類? (編譯器可能能夠推斷出來,但這個人不能大聲笑) – Pharap

回答

1

!Ispostback在頁面加載

如果你不使用它,alwyas當信息去到服務器,你會得到年輕人的價值。

歡呼聲。

+0

Ahhh新我錯過了一些簡單的東西!非常感謝你! – Andy

+0

@安迪不客氣,我們一直都不知道。 –

相關問題