AJAX
| ScriptManager | Needed 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. |
| ScriptManagerProxy | Used inside custom controls that use AJAX extensions instead of ScriptManager to ensure that ScriptManager is not defined twice on the page. |
| UpdatePanel | Defines 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.
|
| UpdateProgress | A 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. |
| Timer | Control 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.Component | Classes that do not render such as Timer. |
| Sys.UI.Control | Extends Component. Typically related to a single DOM element. |
| Sys.UI.Behaviour | Extends Component. Adds functionality to DOM elements for things like mouse over popups etc. |