I have an asp page where controls are dynamically added from the DB on Page_Init() The EnableViewState is set to false.
One of the dynamic controls is a CheckBox and when checked it causes postback.
Now on Page_Init I repopulate my page (after changing according to rules) and the checkbox's checked property is now false.
It stays false up to the end of LoadPageStateFromPersistenceMedium() from what I can see.
protected override object LoadPageStateFromPersistenceMedium()
{
Control cntrl = Page.FindControl("FINS10CopyAddress");
Boolean check = ((CheckBox)cntrl).Checked;
return null;
}
Then suddenly its true again on OnPreLoad().
protected override void OnPreLoad(EventArgs e)
{
Control cntrl = Page.FindControl("FINS10CopyAddress");
Boolean check = ((CheckBox)cntrl).Checked;
}
If I do the same with another control's visible property it works.
Any ideas what can cause this or suggested methods to override to not load previous state ?
The Answer below helped me to create a workaround:
dataValue cntrl = ((Helper)Session["helper"]).Event.Control(Request["__EVENTTARGET"]);
if (cntrl != null)
{
if (cntrl is webCheckBox)
((CheckBox)Page.FindControl(Request["__EVE开发者_如何学JAVANTTARGET"])).Checked = (Boolean)cntrl.Value;
}
EDIT
It is the postback data setting the control, in your LoadPageStateFromPersistenceMedium()
see:
var val = Request[Request["__EVENTTARGET"]];
Unfortunately the Request object is readonly
I don't know of any other way to stop it from setting the value to what it was changed to on the client side except to set the value to what you want it in LoadPageStateFromPersistenceMedium()
after the postbackdata
has been set.
精彩评论