Extenders are great for providing client functionality to
existing server controls in an incremental way. In many cases, however, we do
not want or do not need an external control to wire client components to a server
control. To describe both the server-side and the client-side functionalities
in a single place, we can resort to script controls. In fact, Script controls
are ASP.NET server controls that can provide script references and script
descriptors without relying on an external object.
Generally, if we are writing the control from scratch, we
can safely derive from the base ScriptControl class,
which takes care of registering the script control with the ScriptManager under
the hood. The only difference between coding the control and coding an extender
is that the properties used to configure the client component and the overrides
of the methods defined in the IScriptControl interface
are embedded in the control rather than in a different object.
In some cases we may want to convert an existing control
into a script control. In such a case we have to derive a class from the
existing server control and manually implement interface IScriptControl.
The following sections will introduce to you the IScriptControl interface.
The IScriptControl Interface and Registering the Script
The IScriptControl interface defines
two methods; Listing 8 and the following Table 3 describe their respective
public interface IScriptControl
Gets a collection of script descriptors that represent
control properties to client-side control properties.
Gets a collection of ScriptReference objects that define
script resources required by the control. This method is used to identify one
or more embedded script resources in a control assembly and output them to
Registration with the ScriptManager is necessary in order to
recognize a script control as an Ajax-enabled control. It is a two-step
process similar to that used for extenders.
1. During the PreRender stage, we
call the RegisterScriptControl method, passing the
script control instance as an argument.
2. During the Render stage, you call
the RegisterScriptDescriptors method to register the
Here we are unwilling to chatter too much about the pure
theories. Thus, let us make room for a simple sample to let it tell every