我正在尝试使用asp.net中的复选框/单选按钮列表控件设置我的测验,以匹配此处找到的bootstrap静态变体:http://getbootstrap.com/javascript/#buttons-checkbox-radio
使用以下代码行可以正常工作:
<asp:RadioButtonList ID="rblQuestion1" runat="server" RepeatDirection="Vertical" RepeatLayout="Flow" CssClass="btn-group" data-toggle="buttons">
<asp:ListItem class="btn btn-default radio-inline" Value="1">Answer One</asp:ListItem>
<asp:ListItem class="btn btn-default radio-inline" Value="2">Answer Two</asp:ListItem>
</asp:RadioButtonList>
但我有三个问题:
最后:
这是从浏览器中显示的HTML:
<span id="ContentMain_wizQuestions_rblQuestion1" disabled="disabled" class="aspNetDisabled btn-group" data-toggle="buttons">
<span class="aspNetDisabled">
<input id="ContentMain_wizQuestions_rblQuestion1_0" type="radio" name="ctl00$ContentMain$wizQuestions$rblQuestion1" value="1" disabled="disabled"><label for="ContentMain_wizQuestions_rblQuestion1_0">Answer One</label></span><br>
<span class="aspNetDisabled"><input id="ContentMain_wizQuestions_rblQuestion1_1" type="radio" name="ctl00$ContentMain$wizQuestions$rblQuestion1" value="2" disabled="disabled">
<label for="ContentMain_wizQuestions_rblQuestion1_1">Answer Two</label></span><br>
<span class="aspNetDisabled"><input id="ContentMain_wizQuestions_rblQuestion1_2" type="radio" name="ctl00$ContentMain$wizQuestions$rblQuestion1" value="3" checked="checked" disabled="disabled">
<label for="ContentMain_wizQuestions_rblQuestion1_2">Answer Three</label></span><br>
<span class="aspNetDisabled"><input id="ContentMain_wizQuestions_rblQuestion1_3" type="radio" name="ctl00$ContentMain$wizQuestions$rblQuestion1" value="4" disabled="disabled">
<label for="ContentMain_wizQuestions_rblQuestion1_3">Answer Four</label>
</span>
我相信aspNetDisabled span标签会干扰bootstrap样式。我怎样才能让它们坚持下去,还是有另一种更好的方法来禁用元素?
由于
答案 0 :(得分:1)
阅读以下MSDN文档
那是因为controlRenderingCompatibilityVersion。如果您的框架版本高于4,则此属性将默认设置为“pages controlRenderingCompatibilityVersion =”4.0“
更改controlRenderingCompatibilityVersion =“3.5”,您可以看到class =“aspNetDisabled”将从html中删除。
Web Control facility after .NET version 3.5
方法1:
请在web.config中添加以下内容以删除aspNetDisabled标记
<system.web>
<pages enableEventValidation="true" controlRenderingCompatibilityVersion="3.5" />
</system.web>
方法2:
您最后还可以执行以下操作,从而有效地删除了禁用项目的额外类的插入。
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
WebControl.DisabledCssClass = "";
}