Prev | Current Page 182 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

To work with the HTTP POST mechanism to retrieve data, one implementation would be
for the client to simply read all of the form variables directly. Fortunately, ASP.NET provides a
more organized mechanism to server controls that implement the IPostBackDataHandler
interface.
The IPostBackDataHandler Interface
The IPostBackDataHandler interface is the recommended method to read form post data from
a control in ASP.NET without having to use the Page class and its Request object.
CHAPTER 3 ?–  A SP.NET S TATE MANAGEMENT 109
?– Note In general, we do not recommend that you directly access the Request or Response object provided by
the Page class (HttpContext), as this would interfere with normal page processing. If you need to write to
the output stream, use the HtmlTextWriter class for this purpose.
IPostBackDataHandler also provides a framework to allow the control to raise change events
at a later point in time if the state of the control has changed sufficiently to warrant such an
action. Listing 3-7 shows the interface definition for IPostBackDataHandler. LoadPostData is the
interface method we concentrate on in this section, as it provides the means to retrieve data
posted to the web server.
Listing 3-7. The IPostBackDataHandler Interface Definition
public interface IPostBackDataHandler{
public bool LoadPostData(string postDataKey,
NameValueCollection postCollection);
public void RaisePostDataChangedEvent();
}
On a postback of a web form to the web server, the ASP.


Pages:
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194