Hi,
could you use hardcoded value which indicates empty selection or something?
E.g something which is unique for sure. You could replace that when
databinding initially and use in LoadPostData as basis to check if something
is selected (and let LoadPostData to ber called with
Page.RegisterRequiresPostBack)?
Or: You could also just check if the value in postCollection is null.
Normally when working with DDL, you clear the selection by setting the
SelectedIndex to -1, so perhaps setting SelectedValue to String.Empty in
code (or some hardcode value) could also work.
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke [quoted text, click to view] "Jane Bell" <Jane.Bell@nospam.please.org> wrote in message
news:u6R01FsPGHA.5352@TK2MSFTNGP10.phx.gbl...
>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?
>