J
Jane Bell
I have a webcontrol which renders a select | option html control. I have
implemented
IPostBackDataHandler with LoadPostData looking like this:
public bool LoadPostData(string postDataKey, NameValueCollection
postCollection)
{
string oldSelectedValue = SelectedValue;
string newSelectedValue = postCollection.GetValues(postDataKey)[0];
if (newSelectedValue != null && !oldSelectedValue.Equals(newSelectedValue))
{
SelectedValue = newSelectedValue;
return true;
}
return false;
}
If I select a regular value in the dropdown, it works fine but selecting n
blank value (string.empty) does not cause the LoadPostData method to be
called so it is impossible to deselect a value.
If I add:
if (Page != null)
{
Page.RegisterRequiresPostBack(this);
}
to Page_OnInit then LoadPostData gets called every time, but I get a
NullReferenceException if I select a blank value.
This is because the postCollection does not contain an entry for the control
when I select a blank.
What do It do?
implemented
IPostBackDataHandler with LoadPostData looking like this:
public bool LoadPostData(string postDataKey, NameValueCollection
postCollection)
{
string oldSelectedValue = SelectedValue;
string newSelectedValue = postCollection.GetValues(postDataKey)[0];
if (newSelectedValue != null && !oldSelectedValue.Equals(newSelectedValue))
{
SelectedValue = newSelectedValue;
return true;
}
return false;
}
If I select a regular value in the dropdown, it works fine but selecting n
blank value (string.empty) does not cause the LoadPostData method to be
called so it is impossible to deselect a value.
If I add:
if (Page != null)
{
Page.RegisterRequiresPostBack(this);
}
to Page_OnInit then LoadPostData gets called every time, but I get a
NullReferenceException if I select a blank value.
This is because the postCollection does not contain an entry for the control
when I select a blank.
What do It do?