HomeASP.NET User Information Management for an ASP.NET...
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 Xianzhong Zhu Rating: / 5 January 09, 2008
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:
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.
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:
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.
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: