so we show list of items with checkboxes to capture responses from user.. and we bind it from values received from data store.. after user has provided input and submitted the response.. on server side we always need some value set to compare the responses provided with initial data values to figure out what has changed..
we figured out a simple solution for this in our project.. creating a simple extension of Checkbox webcontrol class.. 'PersistInitialStateCheckbox' class...
[ToolboxData("<{0}:PersistInitialStateCheckbox runat=server>{0}:PersistInitialStateCheckbox>")]
public class PersistInitialStateCheckbox: System.Web.UI.WebControls.CheckBox { ... }
the only purpose of this control was to introduce one extra property 'InitialState' (a boolean value)..
///
/// Initial Value of the dropdown list
///
[Bindable(true),
Description("Initial Value"),
Category("Custom"),
Browsable(true),
DefaultValue("False")]
public bool IntialState {
get {
if(this.ViewState["IntialState"] != null)
{ return (bool)this.ViewState["IntialState"]; }
return false;
}
set { this.ViewState["IntialState"] = value; }
}
which is rendered along with the control..
protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
{
base.AddAttributesToRender(writer);
writer.AddAttribute("InitialValue", IntialState.ToString());
}
so whenever data is posted back.. server code can simply compare the Initial State value with current value..
if (PersistInitialStateCheckbox.IntialState == PersistInitialStateCheckbox.Checked)
{ ... }
Enjoy coding!!! ©
 
courtesy.. Prakash Kalakoti... one of the team members... who did this solution.. :)
ReplyDelete