DefaultAjax WebForm

A new DefaultAJAX.aspx page has been added, which defines the CEWebFormRenderer control in an updatePanel, to participate in Partial Rendering of the page.

The DefaltAJAX Webform is a new default startup page that has been provided for customers to use when they wish to take advantage of the AJAX environment. It is included in the installed files for the ASP.NET Generator and can be found in the ASP.NET Generator\Common\User directory. It comprises three separate files: DefaultAJAX.aspx, DefaultAJAX.aspx.cs, DefaultAjax.aspx.designer.cs.

The diagram below illustrates the DefaultAJAX Web Form in the Visual Studio Designer. A

ScriptManager is defined on the form, which is always required in an AJAX-enabled Web Form. The CEWebformRenderer is defined inside an UpdatePanel so that it can participate in partial page updates.

Figure 34.  DefaultAJAX Web Form in the Visual Studio Designer

DefaultAJAX Web Form in the Visual Studio Designer

The ASP.NET markup for the DefaultAJAX WebForm is shown below. The sections that are relevant to AJAX support are tagged with “<%------>%> to explain the difference between this Web Form and the original Default.aspx which does not take advantage of AJAX.

<%--------------------------------------------------------------------------%>
@ Register TagPrefix="cc1" Namespace="CEWebForm" Assembly="CEWebFormRenderer"
<%--------------------------------------------------------------------------%>
@ Page language="c#" Codebehind="DefaultAJAX.aspx.cs" AutoEventWireup="false"
Inherits="CEASPNETWebForm.WebForm2"
<%--------------------------------------------------------------------------%>
@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp"
<%--------------------------------------------------------------------------%>
@ Register TagPrefix="UniMenuControl" Namespace="ASPGENControls" Assembly="UniMenu"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
      <HEAD id="Head1" runat="server">
            <title id="PageTitle1" runat="server">WebFormAjax</title>
            <meta content="Microsoft Visual Studio .NET 4.6" name="GENERATOR">
            <meta content="C#" name="CODE_LANGUAGE">
            <meta content="JavaScript" name="vs_defaultClientScript">
            <meta content="http://schemas.microsoft.com/intellisense/ie5"
            name="vs_targetSchema">
            <script type="text/javascript" id="UniMenuScriptJS" src="UniMenuScript.js"></
            script>
       </HEAD>
      <body leftMargin="0" topMargin="0">
            <form id="Form1" method="post" runat="server">
            A Script Manager needs to be defined in a Web Form for AJAX Support
            <asp:ScriptManager ID="ScriptManager1" runat="server"
            EnablePartialRendering=true>
            </asp:ScriptManager>
            <script type="text/javascript">
                  Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
                  Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);
                  Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(CheckStatus);
            </script>
            <TABLE id="Table1" style="LEFT: 0px; POSITION: absolute; TOP: 0px; width:
            74%; height: 72%;" cellSpacing="0" cellPadding="0">
                  <TR>
                        <TD vAlign="top" noWrap width="100%" style="height: 100%">
                        The CEWebFormRenderer is included inside an UpdatePanel control
            <asp:UpdatePanel ID="CEWFR_UpdatePanel" runat="server" UpdateMode=
            "Conditional">
            <ContentTemplate>
                  <cc1:cewebformrenderer id="RNDR1" style="LEFT: 0px; POSITION:
                  absolute; TOP: 0px" runat="server"
                  Width="100%" Height="100%"></cc1:cewebformrenderer>
            </ContentTemplate>
            </asp:UpdatePanel>
The UNIMenu control is contained inside a separate UpdatePanel
            <asp:UpdatePanel ID="UniMenu1_UpdatePanel" runat="server" UpdateMode=
            "Conditional">
            <ContentTemplate>
            <unimenucontrol:UniMenu id="UniMenu1" style="LEFT: 0px; POSITION:
            absolute; TOP: 0px" Height="150px" Width="150px"
            ToolTip="Context Menu" ShowAtDesignTime="False"
            RolloverColor="LightGoldenrodYellow" BorderStyle="Outset"
            runat="server">
            <unimenucontrol:UniMenuItem Tooltip="Change to another ispec"
            CommandName="SelectIspec" Text="Select a Form"></unimenucontrol:UniMenuItem>
            <unimenucontrol:UniMenuItem Tooltip="Look at any messages or errors
            from the application." CommandName="ViewMessages"
            Text="View Messages/Errors"></unimenucontrol:UniMenuItem>
            <unimenucontrol:UniMenuItem Tooltip="Change to another language"
            CommandName="ChangeLanguage" Text="Change Language"></unimenucontrol:UniMenuItem>
            <unimenucontrol:UniMenuItem CommandName="" Text="" Tooltip=""></
            unimenucontrol:UniMenuItem>
            <unimenucontrol:UniMenuItem Tooltip="Display and interact with the
            Console window" CommandName="Console" Text="Show Console"></
            unimenucontrol:UniMenuItem>
            <unimenucontrol:UniMenuItem Tooltip="Send the Form to the Printer"
            CommandName="Print" Text="Print Form"></unimenucontrol:UniMenuItem>
            <unimenucontrol:UniMenuItem Tooltip="Send the form data to the host
            application" CommandName="Transmit" Text="Transmit Form"></
            unimenucontrol:UniMenuItem>
            <unimenucontrol:UniMenuItem Tooltip="Close the current Session"
            CommandName="Close" Text="Close Session"></unimenucontrol:UniMenuItem>
            </unimenucontrol:UniMenu>
      </ContentTemplate>
      </asp:UpdatePanel>
      </TD></TR>
      </TABLE>
The UpdateProgress Indicator is declared to provide visual feedback during a
transaction
      <asp:UpdateProgress ID="UP1" runat="server" DynamicLayout=true
      AssociatedUpdatePanelID="CEWFR_UpdatePanel" DisplayAfter="1000">
      <ProgressTemplate> <img style="LEFT: 300px; POSITION: absolute; TOP: 300px"
      src="images\ajax-loader.gif" /></ProgressTemplate></asp:UpdateProgress>
      </form>
      </body>
</HTML>

Notes:

If you are customizing the ASP.NET Client environment and want to use AJAX technology in your application, note the following points. The support for AJAX requires:

  • Any occurrences of the newline character "\n" in sections of Javascript to be removed because the AJAX Script Manager requires this. Otherwise the Javascript is processed correctly.

  • Any call to register script (either Startup or Client script) needs to the corresponding WebFormRenderer method, which registers the Script with the ScriptManager if the page is being partially rendered. For example: RNDR1.RegisterStartupScript("StatusLine", script);