Click here to Skip to main content
15,891,423 members
Articles / Web Development / HTML

AJAX-enabling an ASP.NET website

Rate me:
Please Sign up or sign in to vote.
3.05/5 (14 votes)
13 Dec 2006CPOL3 min read 80.1K   1.1K   35  
To use the ScriptManager and UpdatePanel controls to enable AJAX-style partial page updates.
using System;
using System.Collections.Generic;
using System.ComponentModel;

public static class BugManager
{
	// Do not modify this class.

	private static List<string> _users = new List<string>();
	private static List<Bug> _bugList = new List<Bug>();

	static BugManager()
	{
		InitializeUsernameList();
		InitializeData();
	}

	public static List<Bug> BugList
	{
		get { return _bugList; }
	}

	[DataObjectMethod(DataObjectMethodType.Select)]
	public static IEnumerable<Bug> GetBugsReportedByUser(string username)
	{
		if (string.IsNullOrEmpty(username))
			return BugList;

		return BugList.FindAll(
			delegate(Bug bug)
			{
				return bug.ReportedBy.StartsWith(username,
					StringComparison.OrdinalIgnoreCase);
			}
		);
	}

	private static void InitializeData()
	{
		_bugList.Clear();

		AddNewBug("Error occured when Submit button is clicked.",
			BugPriority.High, BugType.Bug, _users[0]);
		AddNewBug("Null reference exception occurred.",
			BugPriority.High, BugType.Bug, _users[1]);
		AddNewBug("File not found error occurred.",
			BugPriority.High, BugType.Bug, _users[2]);
		AddNewBug("Would like to see the ID when a new item is added.",
			BugPriority.Low, BugType.Enhancement, _users[3]);
		AddNewBug("Difficult to read yellow font on home page.",
			BugPriority.Medium, BugType.Trivial, _users[4]);
		AddNewBug("A sample bug description.",
			BugPriority.High, BugType.Bug, _users[5]);
		AddNewBug("Invalid cast exception occurred.",
			BugPriority.High, BugType.Bug, _users[0]);
		AddNewBug("Index array out of bounds error occurred.",
			BugPriority.High, BugType.Bug, _users[1]);
		AddNewBug("Unauthorized access error occurred.",
			BugPriority.Medium, BugType.Bug, _users[1]);
		AddNewBug("Insufficient memory error occurred.",
			BugPriority.High, BugType.Bug, _users[5]);
		AddNewBug("Page not found error occurred.",
			BugPriority.High, BugType.Bug, _users[5]);
		AddNewBug("Yet another sample bug description.",
			BugPriority.Medium, BugType.Bug, _users[3]);
		AddNewBug("Another sample bug description.",
			BugPriority.Low, BugType.Bug, _users[6]);
	}

	private static void AddNewBug(string bugDescription, BugPriority bugPriority,
		BugType bugType, string reportedBy)
	{
		_bugList.Add(new Bug(bugDescription, bugPriority, bugType, reportedBy));
	}

	private static void InitializeUsernameList()
	{
		_users.AddRange(new string[] { "Johnnie Walker", "John Doe", "Joe Bloggs", 
			"Luke Skywalker", "Erica Cartman", "Petra Salieri", "Erwin Wonderland"});
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
I've worked in the learning software industry for 10+ years, with a background in product development and product marketing. At present, I'm a co-founder and director at InnerWorkings, where we help software developers learn .NET by writing code and solving programming challenges in Visual Studio. I was born in Dublin, Ireland but my family lives in the San Francisco Bay Area.

Comments and Discussions