Extend ASP.NET AJAX Client-Side Function - The Server-Side Way
page 3 of 11
by Xianzhong Zhu
Feedback
Average Rating: 
Views (Total / Last 10 Days): 46720/ 93

About WebControl

Another path to extend ASP.NET AJAX client-side functionalities is via script controls. Script controls are WebControls that can provide script references and script descriptors (i.e. implementing IScriptControl) without relying on an external object (like the first means). We can describe both the server-side and the client-side functionalities in a single place.

In general, if we want to develop the control from scratch, we can safely derive from the base ScriptControl class, which takes the responsibility for registering the script control with the ScriptManager under the hood. Joyfully, programming the control is pretty similar to doing an extender.

One point to note is that the IScriptControl interface, similar to interface IExtenderControl, must be implemented by every script control. Another point to note is that a script control does not have a target control; this is why the RegisterScriptDescriptors method (also to be discussed later) does not receive a reference to the extended control as happened with extenders.

To make clearer the relationships between the objects mentioned above, we list the class definition for class ScriptControl in Listing 2 and give a hierarchical tree between the associated objects in Figure 2.

Listing 2 - The class definition for class ScriptControl

public abstract class ScriptControl: WebControl, IScriptControl
{
  // Fields
  private IScriptManagerInternal _scriptManager;
  // Methods
  protected ScriptControl();
  internal ScriptControl(IScriptManagerInternal scriptManager);
  protected abstract IEnumerable < ScriptDescriptor > GetScriptDescriptors();
  protected abstract IEnumerable < ScriptReference > GetScriptReferences();
  protected override void OnPreRender(EventArgs e);
  protected override void Render(HtmlTextWriter writer);
  IEnumerable < ScriptDescriptor > IScriptControl.GetScriptDescriptors();
  IEnumerable < ScriptReference > IScriptControl.GetScriptReferences();
  // Properties
  private IScriptManagerInternal ScriptManager
  {
    get;
  }
}

Figure 2 - The hierarchical relationships related to ScriptControl

Now, with a general profile in mind, let us examine carefully the above two solutions.


View Entire Article

User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 6:34:12 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search