User and Role Management for an ASP.NET AJAX Server-Centric Based Online Shopping Website - Adding Background Users
(Page 6 of 6 )
Adding Background Users
Clicking the "Add new user" button within the GridView control will redirect the user to another important page, "AddAdminUser.aspx." On the face of it, this part is pretty similar to the user registration discussed before, but here we can assign special kinds of roles to the newly-added user whereas the foreground user registration can not.
Interface Design
When designing this page, we’ve also introduced three ASP.NET AJAX Extender controls: TextBoxWatermarkExtenderto render the watermark effect to the "UserName" TextBox, PasswordStrengthto test the strength of the password the user enters, and ValidatorCalloutExtenderto give a friendlier hint message when the user enters an invalid email address. The following figure 14 gives the corresponding design-time snapshot.
Figure 14—the design-time snapshot for registering background users
/Building_ASP.NET_AJAX_Server-Centric_Shopping_Website(4)_html_m7be4ace4.png)
There’s nearly nothing peculiar here but a DropDownList control named "RoleList" for the manager to select the role!
Page Initialization
There’s only one task to perform in initializing the page: binding data to the "RoleList" DropDownList control.
protected void Page_Load(object sender,EventArgs e) {
///bind data to the control
if(!Page.IsPostBack) {
BindRoleData();
}
}
private void BindRoleData(){
///define the class that gets the data
Role role = new Role();
SqlDataReader recr = role.GetRoles();
///Set the control's data source
RoleList.DataSource = recr;
RoleList.DataTextField = "RoleName";
RoleList.DataValueField = "RoleID";
///bind data to the control
RoleList.DataBind();
///Close the database connection
recr.Close();
}
Here we’ve also appended sufficient comments for readers to refer to. So, let's continue to see the adding operation.
Adding a Background User
The adding function here is also simple.
protected void SureBtn_Click(object sender,EventArgs e){
User user = new User();
int nUserID = user.AddUser(UserName.Text,RealName.Text,Password.Text,
Address.Text,Phone.Text,Mobile.Text,Email.Text,
Int32.Parse(RoleList.SelectedValue),Remark.Text);
Response.Write("<script>alert('" + "Adding operation is successful. Please safekeep your data!" + "');</script>");
}
As you’ve seen, after adding the new user data into the back end database we only need to show the manager a friendly hint message.
Last but not least, when you test this page you should remember the phone and mobile numbers format or modify them according to you own needs.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |