The StateBag Class and the IStateManager Interface

The client-side state management technique ViewState exists in the .NET Framework class hierarchy as a member property of the System.Web.UI.Control class called ViewState, of type StateBag, which implements a dictionary data structure to store name value pairs. The StateBag class implements the interfaces in Table 3-3. Table 3-3. Interfaces Implemented by the StateBag Class Table 3-3. Interfaces Implemented by the StateBag Class Defines enumerators, synchronization methods, and size for...

Capturing the Postback via IPostBackEventHandler

As part of our design, we had the requirement of rendering the button as either a normal button or as a specially configured hyperlink to submit the web form. With events in hand, we now move on to hooking the button click into the postback process through implementation of the IPostBackEventHandler interface. To achieve this, we next implement the single method of the postback interface, RaisePostBackEvent public void RaisePostBackEvent string argument RaisePostBackEvent takes a single...

Repeater Control Event Management

Repeater exposes an ItemCommand event, an ItemCreated event, and an ItemDataBound event. We use the Events collection provided by System.Web.UI.Control to track registered client delegates. The following code for the ItemCommand event is reproduced in a similar manner for the ItemCreated and ItemDataBound events private static readonly object ItemCommandKey new object public event RepeaterCommandEventHandler ItemCommand Events.AddHandler ItemCommandKey, value Events.RemoveHandler...

The GetScriptReferences Method

In order to add AJAX functionality to a custom server control, some JavaScript code is probably required. It is a good convention to create a .js file that has the same name as the custom server control to help keep things organized. This script file must be made available to the control at runtime. The GetScriptReferences method adds references to the required script files at runtime so that they are available to the custom AJAX server control. You can certainly include multiple script files...

Command Events and the RepeaterItem Control

The RepeaterItem control plays a key role in ensuring that Command events are bubbled up to the parent Repeater control so that it can raise an ItemCommand event to the outside world. The following code takes Command events that are bubbled and wraps the events in a custom RepeaterCommandEventArgs object to provide additional information on the event's source protected override bool OnBubbleEvent object source, EventArgs e CommandEventArgs ce e as CommandEventArgs RepeaterCommandEventArgs this,...

Client Callbacks API

The client callback system is anchored on the server side by the ICallbackEventHandler interface implemented by a web form or a server control that wishes to be the target of a client script call. The interface defines two functions that are executed in sequence to receive the parameters from the client through the RaiseCallbackEvent method and then send the response content back via a GetCallbackResult method. void RaiseCallbackEvent string eventArgument string GetCallbackResult The argument...

Rendering Client Script Code

RolloverImageLink takes advantage of most of the features built into ASP.NET via the ClientScriptManager class that is attached to the Page class as a static ClientScript property for emitting JavaScript into the HTML output in a modular manner. This capability includes a registration system that ensures only a single instance of a block of script code is emitted in the final HTML output, despite the presence of multiple instances of a server control that need it on a web form. The...