vb.net 在 asp.net 中启用或禁用 div

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42947971/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 20:13:31  来源:igfitidea点击:

enable or disable a div in asp.net

asp.netvb.net

提问by Hala mahala

hello does anyone knows how to enable and disable a hole div content. i have a div that has a celendar and text boxes as well as dropdownlist etc... and i wanted when the user press a button that the content inside the div was disabled, note that i dont want to make them invisible but enable or disable. Now i know i can make each textbox calendar etc.. disabled individually but i was wondering if there is a way to make the hole div content disabled thus saving some line codes and time. thanks here is the code od the content of the div :

你好有谁知道如何启用和禁用孔 div 内容。我有一个 div,它有一个 celendar 和文本框以及下拉列表等......我希望当用户按下按钮时,div 内的内容被禁用,请注意,我不想让它们不可见,而是启用或禁用. 现在我知道我可以使每个文本框日历等..单独禁用,但我想知道是否有办法禁用孔 div 内容从而节省一些行代码和时间。感谢这里是 div 内容的代码:

 <asp:Calendar ID="mtcDataMR" runat="server" onselectionchanged ="mtcDataMR_SelectionChanged" ></asp:Calendar>
       <br />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <asp:TextBox ID="txtData" runat="server" ReadOnly="True"></asp:TextBox>
      <br />
     </fieldset>
     <fieldset>
          <legend>Filtrar Marca??es</legend>
          <br />
          Nome de Utente<br />
     <asp:CheckBox ID="chkFiltroUtente" text=" " runat="server" AutoPostBack="true" OnCheckedChanged="chkFiltroUtente_CheckedChanged" /><asp:TextBox ID="txtFiltrarNomeUtente" runat="server" AutoPostBack="true" OnTextChanged="txtFiltrarNomeUtente_TextChanged" ReadOnly="True" ></asp:TextBox>
          <br />
          <br />
      <fieldset>
           <legend>Tipo de Marca??es a Mostrar</legend>
              <asp:RadioButton ID="rdbConsultas" text="Consultas" runat="server" GroupName="rdb" AutoPostBack="true" OnCheckedChanged="rdbTratamentos_CheckedChanged" />
              <asp:RadioButton ID="rdbTratamentos" text="Tratamentos" runat="server" GroupName="rdb" Autopostback ="true" Checked="True" />
      </fieldset>
         <br />
         Nome de Especialista<br />
          <asp:CheckBox ID="chkFiltroEspecialista" Text=" " runat="server" /> <asp:DropDownList runat="server" ID="cbxFiltroEspecialista" OnSelectedIndexChanged ="cbxFiltroEspecialista_SelectedIndexChanged" AutoPostBack="true" /> <br />
         Local de Tratamento<br />
          <asp:CheckBox ID="chkFiltroLocal" Text=" " runat="server" /> <asp:DropDownList runat="server" ID="cbxLocal" OnSelectedIndexChanged ="cbxFiltroLocal_SelectedIndexChanged" AutoPostBack="true" /> <br />
         Hora de Inicio<br />
          <asp:CheckBox ID="chkFiltroHora" Text=" " runat="server" /> <asp:DropDownList runat="server" ID="cbxFiltroHora" OnSelectedIndexChanged ="cbxFiltroHora_SelectedIndexChanged" AutoPostBack="true" /> <br />
         <fieldset>
             <legend> Estados a Apresentar</legend>
             <asp:CheckBox ID="chkMRSuspensas" runat="server" text="Mostrar Marca??es Suspensas" AutoPostBack ="true" OnCheckedChanged="chkMRSuspensas_CheckedChanged"></asp:CheckBox>
             <br />
             <asp:CheckBox ID="chkMRCanceladas" runat="server" text="Mostrar Marca??es Canceladas" AutoPostBack="true" OnCheckedChanged="chkMRSuspensas_CheckedChanged"></asp:CheckBox>
         </fieldset>
         <asp:Button text="Limpar Filtros" ID="btnFiltroClear" runat="server" OnClick="btnFiltroClear_Click"  />
      </fieldset>

  </div>

btw what im currently using is (on button click)

顺便说一句,我目前使用的是(点击按钮)

 mtcDataMR.Enabled = False
        txtData.Enabled = False
        chkFiltroUtente.Enabled = False
        rdbConsultas.Enabled = False
        rdbTratamentos.Enabled = False
        chkFiltroEspecialista.Enabled = False
        chkFiltroLocal.Enabled = False
        chkFiltroHora.Enabled = False
        chkMRSuspensas.Enabled = False
        chkMRCanceladas.Enabled = False
        btnFiltroClear.Enabled = False
        cbxFiltroEspecialista.Enabled = False
        cbxLocal.Enabled = False
        cbxFiltroHora.Enabled = False

but as you can see there is so much code lines.

但是正如您所看到的,代码行太多了。

回答by Kamrul Hasan

You can enable or disable a div. write inside the div runat="server" and id="a id name " . Then you can access the div id in .cs page. Now You can enable or disable.

您可以启用或禁用 div。写入 div runat="server" 和 id="a id name " 。然后你就可以在 .cs 页面中访问 div id。现在您可以启用或禁用。

Example:
.aspx page:

示例:
.aspx 页面:

<div runat="server" id="divSearch"> {here you write} </div>

.aspx.cs Page:

.aspx.cs 页面:

divSearch.enable = false; OR divSearch.enable = true;