views:

60

answers:

1

I enable client validation using the Html.EnableClientValidation method in my view. This client-side validation works great for text boxes, but I think I might have found a bug when used with dropdownboxes.

If you use the following construction Html.DropDownList( name, data, "Please choose..." ) without any ViewData-item with that name then client-side validation works great. If you look at the generated HTML code you will see that ASP.NET generated ValidationRules for it in the JSON block.

However, if I add a ViewData-item with that name then the ValidationRules for the client validation is empty!

In both cases, server-side validation works as expected. Bug or is there something that I am missing?

A: 

The solution is simple:

<%= Html.DropDownList("Username", CType(ViewData("Data"), SelectList), "Please choose...")%>

Client-validation does not work if you do it like this:

<%= Html.DropDownList("Username", "Please choose...")%>

In both cases, I use the same code to construct the ViewData item but it only works with the first statement.

hhoang