Click here to Skip to main content
12,250,675 members (45,482 online)
Click here to Skip to main content
Articles » Web Development » Ajax » General » Downloads

Stats

232.8K views
759 downloads
149 bookmarked
Posted

AJAX Was Here - Part 2: ASP.NET Integration

, 2 May 2005
Asynchronous JavaScript and XML with ASP.NET.
AJAX
AJAX
AJAX.csproj.webinfo
bin
AJAX.dll
CallBackHelper.dll
Global.asax
CallBackHelper
bin
Release
CallBackHelper.dll
CallBackHelper.csproj.user
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using WCPierce.Web;

namespace AJAX
{
  public class Article : System.Web.UI.Page
  {
    protected System.Web.UI.WebControls.TextBox txtUsername;
    protected System.Web.UI.WebControls.Label lblMessage;
    protected System.Web.UI.WebControls.Button btnCheckUsername;
  
    private void Page_Load(object sender, System.EventArgs e) { }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      InitializeComponent();
      base.OnInit(e);
    }

    private void InitializeComponent()
    {    
      this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    protected void txtUsername_TextChanged(object sender, System.EventArgs e)
    {
      if( !CallBackHelper.IsCallBack )
        return;

      string uName = txtUsername.Text;

      try
      {
        CallBackHelper.Write( IsUsernameAvailable(uName).ToString() );
      }
      catch( Exception ex )
      {
        CallBackHelper.HandleError( ex );
      }
    }

    protected void btnCheckUsername_Click(object sender, System.EventArgs e)
    {
      string uName = txtUsername.Text;
      if( IsUsernameAvailable( uName ) )
      {
        lblMessage.Text = "PostBack - Username Available!";
        lblMessage.ForeColor = Color.Green;
        lblMessage.Visible = true;
      }
      else
      {
        lblMessage.Text = "PostBack - Username Unavailable!";
        lblMessage.ForeColor = Color.Red;
        lblMessage.Visible = true;
      }

      //Simulate 5 second delay
      System.Threading.Thread.Sleep(5000);
    }

    private bool IsUsernameAvailable( string Username )
    {
      bool isAvailable = true;

      switch( Username.ToLower() )
      {
        case "bill":
        case "william":
        case "christopher":
        case "pierce":
        case "zonebit":
          isAvailable = false;
          break;
      }

      return isAvailable;
    }
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Bill Pierce
Software Developer (Senior)
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 2 May 2005
Article Copyright 2005 by Bill Pierce
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid