如何从代码隐藏中禁用 bootstrap 控件

How to disable bootstrap controls from code behind

我有一个 aspx 页面:

<div class="form-vertical">
    <div class="form-group">

        <div class="row">
            <div class="col-sm-3">
                <asp:DropDownList runat="server" ClientIDMode="Static" ID="ddlLocation" CssClass="form-control required" AppendDataBoundItems="true" DataTextField="location_name" DataValueField="location_id" OnInit="ddllocation_Init">
                    <asp:ListItem Value="" Text="Select location..">
                    </asp:ListItem>
                </asp:DropDownList>
            </div>
        </div>
        <br />

        <div class="row">
            <div class="col-sm-4">
                <button type="button" id="btnAdd" class="btn btn-success pull-center"><i class="fa fa-search"></i>Add</button>
            </div>
        </div>

    </div>

</div>

....
Some more content here that needs to be displayed.

根据特定条件,当 asp.net 页面加载时,我想 隐藏整个 div class="form-vertical" 要么 禁用所有控件

可以禁用 asp.net 控件,但如何禁用按钮 - btnAdd

有什么建议吗?

隐藏Div:给出divid并添加runat="server",以便您可以从代码隐藏中访问相应的div。

<div ID="myDivId" runat="server" >
  //div content
</div>

在代码隐藏中将其 visible 属性 设置为 false

myDivId.Visible = false

要禁用 Button:添加 runat="server"

<button id="myBtn" runat="server"> clickMe </button>

在代码隐藏中

 myBtn.Disabled = true;