Question

I have converted ASP.NET WebForms DropDownList to dynamic loading with the great Select2 library. When I use loading of remote data, I need to use a

<input type="hidden" id="foo" />

that I'll turn into Select2 box with

$(document).ready(function () {
    $("#foo").select2(...);
});

The problem is that when I'm trying to incorporate this into ASP.NET page and set the initial value from a query parameter, I can either use

<input type='hidden' id='foo' value='<%=Request["@id"] %>' class='bigdrop'/>

which I don't like, because I'll have logic in my markup, or

<asp:HiddenField runat="server" ID="foo" ClientIDMode="Static"/> 

and set the value in codebehind, but I am unable to set the class for the input.

Which approach should I use?

Was it helpful?

Solution

there is no CssClass property on HiddenField! But I solved it in jQuery -

$(document).ready(function () {$("#foo").addClass('myclass'); }

Answer by "Axarydax"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top