html - Overriding ASP.NET DropDownList width for responsive website -
if there's case using mvc responsive websites, it:
i'm working on site asp.net webforms, undergoing redesign use responsive markup. impractical convert mvc, have make existing controls.
on particular form page, have 2 combo-boxes on same row; these have css classes appropriately set specify width @ 48%
of parent element. trouble since we're using asp:dropdownlist, control rendered style
attribute having width:275px;
, overrides width set in css class.
in codebehind of composite control containing these dropdownlists (particularly renderchildren
method override), i've tried calling [control].style.clear();
prior calling base method. has no effect; adding:
[control].style.add(htmltextwriterstyle.width, "inherit");
causes element rendered as:
<select style="width:275px;width:inherit;" class="input-half first" id="longandcomplicated" name="longandcomplicated">
note 2 width
declarations, when ideally there shouldn't style
attribute in first place.
i've had poke in reflector @ source, , couldn't find hard-coded width being set; gather style setters being copied somewhere further asp.net hierarchy.
as lucky guess, tried:
- setting
width
empty string on<asp:dropdownlist>
("inherit" causes parse error) - explicitly specifying
width="48%"
- setting
enabletheming="false"
none of these has had positive effect, rendered style
attribute still having width:275px;
.
where width magically being set from? how can override behaviour, ideally without having create derived class inheriting system.web.ui.webcontrols.dropdownlist
?
many thanks.
i have better idea, fix width , do not inherit width, inherit width parent , over-ride width element defined width:275px; meaning less.
i have created fiddle, works fine in chrome, select tag has fixed width,
if sub element size increase automatically grow.
please check fiddle
if question referring css class class="input-half first"
style defined in element style 1 applied @ last , have high priority compare class, better create new class, , assign it.
hope, have answered in right context have written many things reference asp.net control, don't think should problem in majority cases.
Comments
Post a Comment