My Development Notes

By Haemoglobin
3/10/2010 (revision 1)

AJAX

ScriptManagerNeeded on any page that uses AJAX extensions. Responsible for sending the AJAX libraries to the client. Other js files can be referenced in using <Scripts><asp:ScriptReference Name="Script.js"/></Scripts> within the script manager declaration or using ScriptManager1.Scripts.Add(new ScriptReference("Script.js"); Add the Assembly attribute if the js file is embedded as a resource in a dll.
ScriptManagerProxyUsed inside custom controls that use AJAX extensions instead of ScriptManager to ensure that ScriptManager is not defined twice on the page.
UpdatePanelDefines an asyncrhonous postback area. Contains a ContentTemplate tag that then houses the controls contained in the asynchronous update panel.

UpdateMode can be set to Always or Conditional. Always means the panel is refreshed even for other UpdatePanel post back's on the page. Conditional will cause the panel to update only if it's parent updates. Nested child controls won't update unless ChildrenAsTriggers is set to True (default). Setting ChildrenAsTriggers to false the UpdateMode must be set to Conditional. A set of triggers defined (overriding and making the ChildrenAsTriggers setting more specific):

<asp:AsyncPostBackTrigger ControlID="controlID" EventName="Click"/> <asp:PostBackTrigger ControlID="controlID2" EventName="Click"/> can be put inside the Triggers section of the update panel to specify what controls inside or outside of the UpdatePanel cause the postback or asyncpostback.

UpdateProgressA control placed in an UpdatePanel with a label ("Processing...") or image (hour glass) placed in the ProgressTemplate node. By default will display for any update panels asynchronous postback unless the AssociatedUpdatePanelId property is set. A cancel button can also be placed inside the control.
TimerControl placed inside the ContentTemplate of the UpdatePanel with Interval and ontick event handler properties for regular updating of the update panel. The DisplayAfter property defaults to 500 milliseconds.
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ScriptName", script, true); //last boolean to include script tags.

Custom Client Callbacks

public partial class MyPage : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler {

    string _callbackArgs;
    public void RaiseCallbackEvent(string eventArgument) {
        _callbackArgs = eventArgument;
    }

    public string GetCallbackResult() {
        return _callbackArgs;
    }

    protected void Page_Load(object sender, EventArgs e) {
        //Client side function to be called by the server
        string callbackRef = Page.ClientScript.GetCallbackEventReference(this, "args", "ClientCallbackFunction", ""); 

        //Cliend side function that will call the server
        string callbackScript = "function MyServerCall(args)" + "{" + callbackRef + "; }";
        //Looks like
        /*
        function CallTheServer2(arg, context) { 
            WebForm_DoCallback('__Page',arg,ClientCallbackFunction,"",null,false); 
        }
        */

        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyServerCall", callbackScript, true);
    }
}

<script type="text/javascript"> 
function ClientCallbackFunction(args) {
    Label.innerText = args;
}

<asp:DropDownList ID="DropDownListChoice" OnChange="MyServerCall(DropDownListChoice.value)"> 

AJAX Client Library

Can be used to create object oriented classes in javascript with intellisense in visual studio.

Type.registerNamespace("Contoso.Utilities");
Contoso.Utilities.MyClassName.registerClass('Contoso.Utilities.MyClassName', ExtendsClass, Sys.IDisposable);
Contoso.Utilities.MyEnum.registerEnum("Contoso.Utilities.MyEnum");

Events

Sys.Application.add_load(PageLoad); 
function PageLoad(sender) 
{
    //Page load code.
}

Sys.WebForms.PageRequestManager has events: initializeRequest, beginRequest, pageLoading, pageLoaded, endRequest

Classes

Sys.ComponentClasses that do not render such as Timer.
Sys.UI.ControlExtends Component. Typically related to a single DOM element.
Sys.UI.BehaviourExtends Component. Adds functionality to DOM elements for things like mouse over popups etc.

Comments

Powered by BlogEngine.NET 1.6.1.0 | Design by styleshout | Enhanced by GravityCube.net | 1.4.5 Changes by zembian.com | Adapted by HamishGraham.NET
(c) 2010 Hamish Graham. Banner Image (c) Chris Gin