📄 editprofile.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNET.StarterKit.Communities;
using System.Web.Security;
//*********************************************************************
//
// EditProfile Class
//
// Represents the Edit Profile page. The Edit Profile page
// enables users to modify their profile information.
//
//*********************************************************************
public class EditProfile : SkinnedCommunityControl
{
string _skinFileName = "Users_EditProfile.ascx";
RegisterForm ctlRegisterForm;
Panel pnlInvalidUsername;
Panel pnlInvalidEmail;
Button btnUpdate;
//*********************************************************************
//
// EditProfile Constructor
//
// Calls the base SkinnedCommunityControl constructor
// and assigns the default page skin. Also checkes
// whether user is authenticated.
//
//*********************************************************************
public EditProfile() : base() {
// Check Security
if (!objUserInfo.IsAuthenticated)
CommunityGlobals.ForceLogin();
// Assign a default skin file name
if (SkinFileName == null)
SkinFileName = _skinFileName;
}
//*********************************************************************
//
// SkinType Property
//
// Specifies the skins directory where this page's skin file is located.
//
//*********************************************************************
override protected string SkinType {
get { return "ContentSkins"; }
}
//*********************************************************************
//
// UserID Property
//
// Represents the user ID associated with the profile being
// edited.
//
//*********************************************************************
private int UserID {
get { return (int)ViewState["UserID"]; }
set { ViewState["UserID"] = value; }
}
//*********************************************************************
//
// InitializeSkin Method
//
// Retrieves all the controls from the Page Skin
//
//*********************************************************************
override protected void InitializeSkin(Control skin) {
// Disable Smart Navigation
Page.SmartNavigation = false;
// Find the Register Form control
ctlRegisterForm = (RegisterForm)GetControl(skin, "ctlRegisterForm");
// Find the Invalid Username Panel
pnlInvalidUsername = (Panel)GetControl(skin, "pnlInvalidUsername");
pnlInvalidUsername.Visible = false;
// Find the Invalid Email Panel
pnlInvalidEmail = (Panel)GetControl(skin, "pnlInvalidEmail");
pnlInvalidEmail.Visible = false;
// Find the Update button
btnUpdate = (Button)GetControl(skin, "btnUpdate");
btnUpdate.Click += new EventHandler(btnUpdate_Click);
}
//*********************************************************************
//
// OnLoad Method
//
// Assigns values to the controls from the page skin.
//
//*********************************************************************
override protected void OnLoad(EventArgs e) {
EnsureChildControls();
if (!Page.IsPostBack) {
// Get Current User Profile information
ProfileInfo objProfile = UserUtility.GetProfile(objUserInfo.Username);
UserID = objProfile.ID;
ctlRegisterForm.Username = objProfile.Username;
ctlRegisterForm.Password = objProfile.Password;
ctlRegisterForm.Email = objProfile.Email;
ctlRegisterForm.FirstName = objProfile.FirstName;
ctlRegisterForm.LastName = objProfile.LastName;
ctlRegisterForm.Timezone = objProfile.Timezone;
ctlRegisterForm.Occupation = objProfile.Occupation;
ctlRegisterForm.Location = objProfile.Location;
ctlRegisterForm.Interests = objProfile.Interests;
ctlRegisterForm.MSN = objProfile.MSN;
ctlRegisterForm.Yahoo = objProfile.Yahoo;
ctlRegisterForm.AIM = objProfile.AIM;
ctlRegisterForm.ICQ = objProfile.ICQ;
ctlRegisterForm.Url = objProfile.Url;
ctlRegisterForm.FakeEmail = objProfile.FakeEmail;
ctlRegisterForm.EnableNewsletter = objProfile.EnableNewsletter;
ctlRegisterForm.EnableNotifications = objProfile.EnableNotifications;
}
}
//*********************************************************************
//
// btnUpdate_Click Method
//
// Updates user profile information or displays error message
// to user.
//
//*********************************************************************
private void btnUpdate_Click(Object s, EventArgs e) {
if (Page.IsValid) {
ProfileInfo objProfile = new ProfileInfo();
objProfile.ID = UserID;
objProfile.Username = ctlRegisterForm.Username;
objProfile.Password = ctlRegisterForm.Password;
objProfile.Email = ctlRegisterForm.Email;
objProfile.FirstName = ctlRegisterForm.FirstName;
objProfile.LastName = ctlRegisterForm.LastName;
objProfile.Timezone = ctlRegisterForm.Timezone;
objProfile.Occupation = ctlRegisterForm.Occupation;
objProfile.Location = ctlRegisterForm.Location;
objProfile.Interests = ctlRegisterForm.Interests;
objProfile.MSN = ctlRegisterForm.MSN;
objProfile.Yahoo = ctlRegisterForm.Yahoo;
objProfile.AIM = ctlRegisterForm.AIM;
objProfile.ICQ = ctlRegisterForm.ICQ;
objProfile.Url = ctlRegisterForm.Url;
objProfile.FakeEmail = ctlRegisterForm.FakeEmail;
objProfile.EnableNewsletter = ctlRegisterForm.EnableNewsletter;
objProfile.EnableNotifications = ctlRegisterForm.EnableNotifications;
int result = UserUtility.UpdateProfile(objProfile);
// Either Update Profile or display error message
switch ( result ) {
case 0: // Success!
FormsAuthentication.SetAuthCookie(objProfile.Username, false);
Context.Response.Redirect(CommunityGlobals.CalculatePath("Users_ShowProfile.aspx"));
break;
case 1: // Username already taken
pnlInvalidUsername.Visible = true;
pnlInvalidEmail.Visible = false;
break;
case 2: // Email address already taken
pnlInvalidEmail.Visible = true;
pnlInvalidUsername.Visible = false;
break;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -