User Information Management for an ASP.NET AJAX Server-Centric Based Online Shopping Website

In this seventh part of an eleven-part series, we will research common user information management tasks. This includes the topics of changing the password, modifying personal information, viewing private information, viewing the order information (discussed earlier), and more.

Contributed by
Rating: 5 stars5 stars5 stars5 stars5 stars / 5
January 09, 2008
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

A downloadable .rar file is available for this article.

User Information Center

Let's begin by discussing how to provide a feature that allows the users to modify their passwords.

Editing Password

This part is done through the "EditUserPwd.aspx" page whose design-time snapshot is shown in Figure 24 below.


Figure 24—the page for the common users to edit password

First of all, the ScriptManagercontrol is a must. Second, the Toolkit control PasswordStrengthmaybe the only thing that attracts our attention. Yes, as you may have imagined, when the user wants to change his password, besides verifying his old password with data in the database, we use the PasswordStrengthcontrol to confirm the safety strength of the newly-entered password and give him a friendly hint. Besides this, we have also leveraged two Validators, theRequiredFieldValidatorand the CompareValidatorto make sure the user enters the proper new password.

The following only lists the code that is associated with the event handler of the "OK" button:

protected void SureBtn_Click(object sender,EventArgs e){

User user = new User();

SqlDataReader dr = user.GetUserLogin(UserName.Text.Trim(),OldPassword.Text.Trim());

///read the value of UserID

string sUserID = "";

if(dr.Read()) { sUserID = dr["UserID"].ToString(); }

///Close the data source

dr.Close();

///judge whether the old password he enters is correct or not

if(sUserID == null || sUserID == "" || sUserID.Length < 0){

Response.Write("<script>alert('" + "The old password is invalid. Please enter again!"

+ "');</script>");

return;

}

///Change the user password

user.UpdateUserPwd(nUserID,NewPassword.Text.Trim());

Response.Write("<script>alert('" + "You have successfully modified the password. Keep your data safely!"

+ "');</script>");

}

Here, there are already enough comments. The entire logic is easy to grasp, isn’t it?

Modifying Personal Info


Modifying Personal Info

This part is done through the "EditUserPwd.aspx" which is invoked by the  "UserManage.aspx" page. The design-time snapshot of this page is shown in Figure 25 below.


Figure 25—the design-time snapshot for the users to edit private info

As you’ve seen from the above figure, this page is still pretty simple, mainly with several textboxes for the user to edit his private information. However, to obtain a better user experience we can fully use the TextBoxWatermarkExtender, PopupControlExtender, ValidatorCalloutExtender, or even UpdatePanelto achieve this kind of effect. Here, for simplicity, we have only bound four ValidatorCalloutExtender controls to four Validators (i.e. RegularExpressionValidator1, RegularExpressionValidator2, RegularExpressionValidator3,RequiredFieldValidator4) that are in turn bound to the four TextBox controls Email, Phone, Mobile, and Email respectively to give the user more intuitive hints when he inputs invalid data into the related fields.

Page Initialization


Page Initialization

When the page is initialized, we should finish the task of loading the original user data and display it to them.

protected void Page_Load(object sender,EventArgs e) {

///Get the value of the parameter

if(Request.Params["UserID"] != null) {

if(Int32.TryParse(Request.Params["UserID"].ToString(),out nUserID) == false) {

return;

}

}

if(!Page.IsPostBack) {

///bind data to the control

if(nUserID > -1) {

BindUserData(nUserID);

}

}

SureBtn.Enabled = nUserID <= -1 ? false : true;

}

private void BindUserData(int nUserID) {

///Get the data

User user = new User();

SqlDataReader recr = user.GetSingleUser(nUserID);

///Read the data

if(recr.Read()){

///display data

UserName.Text = recr["UserName"].ToString();

RealName.Text = recr["RealName"].ToString();

Email.Text = recr["Email"].ToString();

Phone.Text = recr["Phone"].ToString();

Mobile.Text = recr["Mobile"].ToString();

Remark.Text = recr["Remark"].ToString();

Address.Text = recr["Address"].ToString();

}

recr.Close(); ///Close the data source

}

Here we still provide enough comments to which you can refer. Please remember that no matter which page you analyze in this sample, the basic initialization logic is quite similar. That will help you find your focus.


Submitting the Modification

Clicking the "OK" button will trigger its corresponding event handler, as follows:

protected void SureBtn_Click(object sender,EventArgs e){

User user = new User();

user.UpdateUser(nUserID,RealName.Text,

Address.Text,Phone.Text,Mobile.Text,

Email.Text,Remark.Text);

Response.Write("<script>window.alert('Changing user info successfully!')</script>");

}

Here, we first create an instance of the User class, and then invoke its UpdateUser member functionto finally submit the personal information to change the server side database. That’s it. As for the inner workings relating to UpdateUseritself, please refer to the downloadable source code accompanying this article.

Viewing Personal Info


Viewing Personal Info

This part of the function is easily accomplished through the "UserInfo.aspx" page, whose design-time snapshot is shown in Figure 26.


Figure 26—the design-time snapshot for personal info viewing

As you may have guessed, this page is only for browsing, so we just need to display the original information. Since the programming logic is quite similar to that of the code discussed above and even much easier, we only give the code that is responsible for loading the user information and binding it to the related fields as follows:

protected void Page_Load(object sender,EventArgs e){

if(Session["UserID"] != null) {

nUserID = Int32.Parse(Session["UserID"].ToString());

}

else{

///Get the value of the parameter

if(Request.Params["UserID"] != null) {

if(Int32.TryParse(Request.Params["UserID"].ToString(),out nUserID) == false) {

return;

}

}

}

if(!Page.IsPostBack)

{ ///bind data to the control

if(nUserID > -1)

{

BindUserData(nUserID);

}

}

}

private void BindUserData(int nUserID) {

///Get the data

User user = new User();

SqlDataReader recr = user.GetSingleUser(nUserID);

///Read the data

if(recr.Read()){

///display data

UserName.Text = recr["UserName"].ToString();

RealName.Text = recr["RealName"].ToString();

Email.Text = recr["Email"].ToString();

Phone.Text = recr["Phone"].ToString();

Mobile.Text = recr["Mobile"].ToString();

Remark.Text = recr["Remark"].ToString();

Address.Text = recr["Address"].ToString();

}

recr.Close(); ///Close the data source

}


blog comments powered by Disqus
ASP.NET ARTICLES

- Implementing ASP.NET 4.0 Page.MetaDescriptio...
- ASP.Net Development Tips
- Intro to Sessions in ASP.Net
- Google Maps API Introduction in ASP.NET usin...
- Creating an ASP.NET 3.5 Gridview Image Galle...
- Encrypt QueryString in ASP.NET 3.5 using VB....
- ASP.NET 3.5 Drop Down List Controls
- Connect to Access Database with ASP.Net
- Secure Audio Streaming with ASP.Net and Flash
- Dynamic Sitemap and Navigation in ASP.Net
- Implement Gzip and Deflate Compression in AS...
- Run ASP.Net in Ubuntu with Apache
- ASP.Net Mono Website Contact Forms
- ASP.Net URL Rewriting Methods
- Murach`s ASP.NET 4 Web Programming with C# 2...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials