Click here to Skip to main content
15,885,881 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.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>Default Page</title>
	<link href="Styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<form id="BugSiteForm" runat="server" defaultbutton="SearchButton">
		<div>
			<h1>
				Bugs List
			</h1>
			<!--
				Todo:
				The Default.aspx page contains a ScriptManager control that allows
				 partial page rendering.
			-->
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>

			<asp:ObjectDataSource ID="BugsDataSource" runat="server" TypeName="BugManager" 
					EnableViewState="False" SelectMethod="GetBugsReportedByUser">
				<SelectParameters>
					<asp:ControlParameter ControlID="SearchText" Name="username" 
						PropertyName="Text"	Type="String" />
				</SelectParameters>
			</asp:ObjectDataSource>
			Reported By:
			<asp:TextBox ID="SearchText" runat="server" />
			<asp:Button ID="SearchButton" runat="server" Text="Search" />
			<hr />
			<!--
				Todo:
				The BugView GridView control and the PanelUpdateTimeLabel Label control 
				 in the Default.aspx page are encapsulated inside an UpdatePanel control 
				 called BugListUpdatePanel.
			-->
			<!--
				Todo:
				The BugListUpdatePanel UpdatePanel control in the Default.aspx page
				 defines a trigger that asynchronously refreshes the contents of this
				 UpdatePanel control when the Click event of the SearchButton Button
				 control is raised.
			-->
            <asp:UpdatePanel ID="BugListUpdatePanel" runat="server">            
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="SearchButton" EventName="Click" />
                </Triggers>
                <ContentTemplate>                
                    <asp:Label ID="PanelUpdateTimeLabel" runat="server" />
			        <asp:GridView ID="BugView" runat="server" DataSourceID="BugsDataSource" 
					        EnableViewState="False"	AutoGenerateColumns="False" 
					        AllowPaging="True" PageSize="8">
				        <Columns>
					        <asp:BoundField DataField="Priority" HeaderText="Priority" />
					        <asp:BoundField DataField="Description" HeaderText="Description" />
					        <asp:BoundField DataField="Type" HeaderText="Type" />
					        <asp:BoundField DataField="ReportedBy" HeaderText="Reported By" />
				        </Columns>
				        <EmptyDataTemplate>
				        No matching users found.
				        </EmptyDataTemplate>
			        </asp:GridView> 		        
			    </ContentTemplate>	
            </asp:UpdatePanel>
			<br /><br />
			   


			<br />
			<asp:Label ID="PageUpdateTimeLabel" runat="server" />
		</div>
	</form>
</body>
</html>

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