search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Filtering the resources dynamically (e.g. using a DropDown) with EnableViewState="false"

Asked by Dan Letecky
15 years ago.

A comment based on a recent support issue:

Changing the Resources collection with ViewState turned off is a bit tricky. Resources collection can be defined in several ways:

1) When you have ViewState turned on, the Resources collection is persisted between calls (at the cost of extra bandwidth, it goes with every request back and forth).

Note: If you are recreating the Resources collection during PostBack or CallBack, remember to clear it first using DayPilotScheduler.Resources.Clear().

2) If you have ViewState turned off but the Resources collection is defined statically in the .aspx file there is no problem because the Resources collection is reconstructed during every request from the .aspx declaration.

3) The most complicated scenario is when you define the Resources dynamically and the actual content depends on a control (e.g. a DropDown), with EnableViewState="false". Here you have to remember to fill the Resources collection during every page load (i.e. preferably in the Page_Load method).

For PostBacks, you can read the state of the DropDown as usual.

For CallBacks (where the state of any other control is not available so you can't check), you have to use the .clientState property in the same way it's used for the search filter in the main demo page (Scheduler/Default.aspx). That means storing the value of the dropdown during every selection change before calling commandCallBack().

Something like this (JavaScript handler of DropDown selection change):

dps1.clientState.resFilter = document.getElementById('yourdropdownid').value;
dps1.commandCallBack('reload');
In the Page_Load:
string filter = "defaultFilter";
if (Page.IsCallBack) {
  filter = (string)DayPilotScheduler1.ClientState["resFilter"];
}
else if (IsPostBack) {
  filter = DropDownFilter.SelectedValue;
}

switch (filter) {
  case "first":
  DayPilotScheduler1.Resources.Clear(); // to make sure it's empty when ViewState is on
  // fill Resources collection
  // ....
}

Just a final note - you might find it easier to turn the ViewState on (I wouldn't be afraid of the slowdown so much) to get rid of the clientState trick.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.