Hello,
I'm using the ValueChanged event in code behind and want to compare the user's input (EnableCustomValues is true so that the user can enter parts of the drop down list item values) with some values in a list. Which should not be a problem since the DropDownValueChangedEventArgs parameter has a "NewValue" property.
The NewValue property contains the text the user has typed or selected from the list (the "TextField" value, not the "ValueField" value which is what I thought first), but it contains the text in a not comparable form. E. g.:
The NewValue string has spaces replaced with "%20" etc. which I know does take place in some pages in the web. The item's text as well as the selected text is always shown correctly (i. e. without the replacement). However if I compare the NewValue with the entries in the list I cannot find the text.
I'm not sure I this is a problem of the web server or application configuration or if it is a bug of the WebDropDown.
Has anyone seen this behaviour and/or does anyone know how to avoid it?
Hello Berhhardus,
This is the behavior by design. In order to send special characters from and to the Server they are encoded additionally.
If you want to use the real value from “CurrentValue/NewValue” property I can suggest you to do this in the following way:
string htmlValue = WebDropDown1.CurrentValue;
string decoded = HttpUtility.UrlDecode(htmlValue);
Label1.Text = decoded;
If you have further questions let me know.
Thank you. So easy - I might have known. Sometimes you can't see the wood for the trees.