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
Listing 2 - The class definition for class
public abstract class ScriptControl: WebControl, IScriptControl
private IScriptManagerInternal _scriptManager;
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();
private IScriptManagerInternal ScriptManager
Figure 2 - The hierarchical relationships related
Now, with a general profile in mind, let us examine
carefully the above two solutions.