This is a migrated thread and some comments may be shown as answers.

[Solved] Add custom HTML attributes to a DropDownList's input tag

1 Answer 71 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bertrand
Top achievements
Rank 1
Bertrand asked on 19 Jul 2011, 02:13 PM
Hi,

I'm trying to add HTML attributes to the hidden input of the DropDownList. I've tried using the DropDownHtmlAttributes() method, but it doesn't seem to do anything.

@(Html.Telerik().DropDownListFor( x => x.value )
    .BindTo( list )
    .DropDownHtmlAttributes( new Dictionary<string, object> {
        { "data-foo", "baz" },
        { "data-bar", "random" }
    } )
)

Is how I'm binding the data to my DropDownList. Is there a way to have my attributes added to the hidden input tag?

I suppose this issue is very much related to Client side validation on a DropDownList (data-val, data-val-required and such don't get added to the input).

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 19 Jul 2011, 02:48 PM
Hello Bertrand,

DropDownHtmlAttributes are applies to the dropdown, which appears when you click on the component.

I am afraid there is no built-in way to apply attributes to the hidden input element. You can do that manually with Javascript.

Best wishes,
Dimo
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
ComboBox
Asked by
Bertrand
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or