【问题标题】:How to disable bootstrap controls from code behind如何从后面的代码中禁用引导控件
【发布时间】:2020-01-12 18:29:22
【问题描述】:

我有一个 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

有什么建议吗?

【问题讨论】:

    标签: asp.net code-behind


    【解决方案1】:

    隐藏Div:给div id 并添加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;
    

    【讨论】:

      猜你喜欢
      • 2016-05-12
      • 1970-01-01
      • 2016-08-21
      • 2012-03-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-25
      • 1970-01-01
      相关资源
      最近更新 更多