ASP.NET
  Home arrow ASP.NET arrow Page 2 - Building the User Interface for an ASP.NET...
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

Building the User Interface for an ASP.NET AJAX Client-Centric Wiki Application
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-10-10

    Table of Contents:
  • Building the User Interface for an ASP.NET AJAX Client-Centric Wiki Application
  • Client-side Programming
  • Registration
  • Managing the Article Categories

  • 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


    Building the User Interface for an ASP.NET AJAX Client-Centric Wiki Application - Client-side Programming


    (Page 2 of 4 )

    When you look into the code for this page, you'll find the markup associated with our Login and Logout button, which looks like this:

    <a href="<%= ResolveUrl("~/Register.aspx") %
    >">Register</a>&nbsp;&nbsp;

    <button id="ButtonLogin" onclick="OnClickLogin();"
    class="mybutton" >Log in</button>&nbsp;

      <button id="ButtonLogout" class="mybutton"

       onclick="OnClickLogout();" style="visibility: hidden;">

        Log out</button>

    <a id="backhome" href="<%=ResolveUrl("~/Default.aspx") %>"
    style="visibility: hidden;">Back to Home Page</a>

    .....(omitted)

     

    You can see that when you click the Login button, it calls the "OnClickLogin();" script. Below is the related code snippet:

      function SetDefaultLoginCompletedCallBack(){.....(omitted)}

      function SetDefaultLogoutCompletedCallBack(){.....(omitted)}

      function SetDefaultFailedCallBack(){.....(omitted)}

      function OnClickLogin() {

       SetDefaultLoginCompletedCallBack();

       SetDefaultLogoutCompletedCallBack();

       SetDefaultFailedCallBack();

    Sys.Services.AuthenticationService.login($get('username').value,

    $get('password').value, false,null,null,null,null,"User
    Context");

    }

      function OnClickLogout(){

    //clear the authentication related cookie and log off

    Sys.Services.AuthenticationService.logout(null, null, null,
    null);

    }

    ..... (Omitted)

      function OnFailed(error, userContext, methodName)

    {..... (Omitted)}

      function OnLogoutCompleted(result){ .....(Omitted)}

    As advised in the official materials, we've first specified three default callback functions for the subsequent authentication service. Next, we call Sys.Services.AuthenticationService.login to try to log into the system using the passed parameters. The following shows the detailed signature for the  Sys.Services.AuthenticationService.login method.

    Sys.Services.AuthenticationService.login(userName, password,

      isPersistent, customInfo, redirectUrl,

       loginCompletedCallback, failedCallback, userContext);

    Since the parameters are self-explanatory and the online materials have provided detailed information, we will not spend any more time on this. From the above code listing, however, you can easily singled out the most interesting and important parameter-loginCompletedCallback, which is a pointer attached to the callback function that is invoked when the login completes. Here is its related code:

    function OnLoginCompleted(validCredentials,userContext,
    methodName)

    {

      if (validCredentials == true)

    {

      $get('loggingInMsg').style.visibility = "visible";

      $get('loginFailureMsg').style.visibility = "hidden";

      $get('buttonLogin').style.visibility = "hidden";

      $get('buttonLogout').style.visibility = "visible";

      $get("backhome").style.visibility = "visible";

      $get("logoutOK").style.visibility = "hidden";

    //window.setTimeout("window.location.href('default.aspx')",
    2000);

    }

      else{

       $get('loggingInMsg').style.visibility = "hidden";

       $get('loginFailureMsg').style.visibility = "visible";

       $get('buttonLogin').style.visibility = "visible";

       $get('buttonLogout').style.visibility = "hidden";

       $get("backhome").style.visibility = "visible";

       $get("logoutOK").style.visibility = "hidden";

     }

    }

    Apparently, when the calling succeeds we give the user two choices: going back to the homepage, or logging out of the system by clicking the Logout button. Of course, you can uncomment the above line "window.setTimeout..." to navigate the valid user to the homepage. You see, all of the underground work has been hidden by the developers by leveraging merely one static class: Sys.Services.AuthenticationService. However, from the client-side JavaScript, with this class we can easily achieve the aim of authentication using the standard ASP.NET 2.0 membership application service.

    There is also one point here worth noticing. Unlike the early Atlas July Preview in which there was another method - validateUser provided by Sys.Services.AuthenticationService -- for the developers themselves to validate the user (establishing their identity and permissions), in the present ASP.NET AJAX 1.0 method, validateUser is removed, letting the system or elsewhere perform these tasks. This is comprehensible because safety is always the most important task in real applications.

    As with the traditional ASP.NET 2.0, to enable the login functionality and forms authentication there is a lot of other work to do, such as enabling the Authentication Service via web.config, making sure the browser has cookies enabled, configuring access to the Membership database via machine.config file, and creating roles, their related users and specifying their accessing rules via the ASP.NET Web Site Administration tool. However, to make a long story short, we omit all of these things but recommend you research carefully into the web.config file accompanying the source code, as well as refer to the online tutorial titled "Using Forms Authentication with ASP.NET AJAX."

    More ASP.NET Articles
    More By Xianzhong Zhu


     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - 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





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