ASP.NET
  Home arrow ASP.NET arrow Page 2 - User and Role Management for an ASP.NET AJ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

User and Role Management for an ASP.NET AJAX Server-Centric Based Online Shopping Website
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2007-12-19

    Table of Contents:
  • User and Role Management for an ASP.NET AJAX Server-Centric Based Online Shopping Website
  • Role Management
  • New Role
  • User Management
  • Deleting the Selected User
  • Adding Background Users

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


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


    (Page 2 of 6 )

      

    First, let’s take a quick glimpse at the running-time snapshot for role management, as is shown in Figure 10 below.


    Figure 10—the running-time snapshot for role management

    On the left of this simple page there already exist three typical roles: Super Administrator, Supplier, and Common Customer. On the right of the page there are two image-styled buttons with the first pointing to the "EditRole.aspx" page and the second triggering the action to delete the selected role on the left, respectively.


    Let’s see the related code when the page is loaded, as follows:

    protected void Page_Load(object sender, EventArgs e) {

    //bind data to the control

    if(!Page.IsPostBack) {

    BindRoleData();

    }

    ///add the dialog that confirms the user to make the deletion

    deleteBtn.Attributes.Add("onclick","return confirm('Are you sure to delete the selected items?');");

    }

    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();

    }

    As the above comments indicate, we first bind the corresponding data to the "RoleList" ListBox control by calling a helper function named BindRoleData. Then we attach a client-side click handler to the "deleteBtn" button by invoking the Addmethod of its collection member —Attributes. When the user selects one of the roles on the left side of the page, the deletion-operation-related event handler will be triggered. The following lists the associated code snippet:

    protected void deleteBtn_Click(object sender,ImageClickEventArgs e){

    if(RoleList.SelectedIndex <= -1) {

    Response.Write("<script>window.alert('Please select the item.')</script>");

    return;

    }

    ///define the classRole

    Role role = new Role();

    ///delete data

    role.DeleteRole(Int32.Parse(RoleList.SelectedValue));

    ///display the info of the operating result

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

    ///rebind data

    BindRoleData();

    }

    Since the code is well commented, we won't discuss it much. The only point that needs to be noticed is that after the deletion is finished the "RoleList" ListBox is updated.

    More ASP.NET Articles
    More By Xianzhong Zhu


     

    ASP.NET ARTICLES

    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ
    - Developing a Dice Game Using ASP.NET Futures...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT