Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
860
DropDownDownValueChangedEventArgs and spaces / special characters
posted

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.:

  • NewValue="0101%20%5Bblah%5D"
  • the text the user has selected from the list (or entered) is "0101 [blah]"

 

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?

Parents
  • 15979
    Verified Answer
    posted

    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.

Reply Children
No Data