Avoiding ViewState - problem with CheckBoxList event handling

P

Per Bergland

To avoid the bulky VIEWSTATE data in my html pages I put most of my
state in the session object, turn off EnableViewState for my Web
Controls and modify the Web Controls in the Page PreRender event.

This works fine for most controls, but when I do this for the
CheckBoxList the event handling doesn't work anymore.

In the Page Load event, I can see the event getting triggered but it
stops somewhere on the way to my event handler:

private void Page_Load(object sender, System.EventArgs e) {
if (!Page.IsPostBack) {
StoreInitialState();
}
else {
// Which element is posting back?
System.Web.HttpRequest request = Page.Request;
System.Collections.Specialized.NameValueCollection formValues =
request.Form;
string target = formValues["__EVENTTARGET"];
if (target.StartsWith("cblLayers")) {
cblLayers_SelectedIndexChanged(this, EventArgs.Empty);
}
}

The above code seems to work (target will be e.g. "cblLayers:0" for the
first row), but surely there must be a more elegant way?
It's not quite clear from the call stack or the documentation which part
of the page init/load/prerender handling it is that calls the control
event handlers. Can someone explain this?

/Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top