Click here to Skip to main content
15,886,689 members
Articles / Web Development / HTML

Magic AJAX: Applying AJAX to your existing Web Pages

Rate me:
Please Sign up or sign in to vote.
4.82/5 (72 votes)
28 May 2007MIT12 min read 968.3K   2.7K   251  
How to apply AJAX technologies to your web pages without replacing ASP.NET controls and/or writing JavaScript code.
<%@ Page language="C#" MasterPageFile="~/MasterPage.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
	
  <asp:WebPartManager ID="WebPartManager1" runat="server" Personalization-Enabled="true" />
  <ajax:ajaxpanel ID="Ajaxpanel1" runat="server">
  
  <fieldset>
		<legend>ASP.NET 2.0 WebParts demo <asp:LinkButton runat="server" id="Toggle" Text="[Switch to EditMode]" OnClick="Toggle_Click" /></legend>
		<i>Very cool demo of ASP.NET 2.0 WebParts running on MagicAjax.<br />Switch to EditMode and move/add/delete WebParts without a visible postback.<br />
		Note: Your modifications are stored in Session, so will be lost when you leave this site.<br />
		Note2: Dragging and dropping of WebParts is a ASP.NET 2.0 feature that is only supported for IE.</i><br /><br />
		<table width="100%"><tr><td valign="top" width="30%">
			<asp:WebPartZone runat="server" ID="WebPartZone1" Width="100%">
					<PartTitleStyle CssClass="WebPartTitle" BackColor="LightBlue" />
					<ZoneTemplate>
						<uc1:Logo ID="Logo1" runat="server" />
					</ZoneTemplate>
			</asp:WebPartZone>
			</td><td valign="top" width="30%">
			<asp:WebPartZone  runat="server" ID="WebPartZone2" Width="100%">
					<PartTitleStyle CssClass="WebPartTitle" BackColor="LightBlue" />
					<ZoneTemplate>
						<uc1:Calendar ID="Calendar1" runat="server" />
					</ZoneTemplate>
			</asp:WebPartZone>
			</td><td width="10%">&nbsp;
		</td><td valign="top" width="30%">
			<asp:CatalogZone ID="CatalogZone1" runat="server">
				<HeaderStyle BackColor="Khaki" />
				<FooterStyle BackColor="Khaki" />
				<CloseVerb Visible="false" />
				<HeaderCloseVerb Visible="false" />
				<ZoneTemplate>
					<asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server" Title="Catalog">
						<WebPartsTemplate>
							<uc1:Logo ID="Logo1" runat="server" />
							<uc1:Calendar ID="Calendar1" runat="server" />
						</WebPartsTemplate>
					</asp:DeclarativeCatalogPart>
				</ZoneTemplate>
			</asp:CatalogZone>
		</td></tr></table>
	</fieldset>
  </ajax:ajaxpanel>
</asp:Content>

<script language="C#" runat="server">
	
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			// Force setting of Session id (workaround for bug in MagicAjax)
			Session["dummy"] = "dummy";
			
			// Authenticate user with dummy userName, so the WebPartManager will allow
			// switching to Editmode.
			FormsAuthentication.SetAuthCookie("dummy", false);
		}
	}

	protected void Toggle_Click(object sender, EventArgs e)
	{
		if (WebPartManager1.DisplayMode == WebPartManager.BrowseDisplayMode)
		{
			Toggle.Text = "[Switch to ViewMode]";
			WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;
		}
		else
		{
			Toggle.Text = "[Switch to EditMode]";
			WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode;
		}
	}
</script>

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 MIT License


Written By
Web Developer
Greece Greece
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions