0

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 :

 <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.

Hala mahala
  • 151
  • 2
  • 4
  • 20
  • Possible duplicate http://stackoverflow.com/questions/15555295/how-to-disable-div-element-and-everything-inside . In the link you can observe how to do this only on client side without need of manipulating backend. – Rafał Czabaj Mar 22 '17 at 09:57
  • i wanted to programmatically enable or disable in a webform(server-side) – Hala mahala Mar 22 '17 at 09:58
  • From what I've remember you can put all controls inside a Panel control and then Enabled property works for everything inside. Second option is div, my question is does your "div" have runat="server" property so you could use it on code behind? – Rafał Czabaj Mar 22 '17 at 10:03

1 Answers1

2

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.

Example:
.aspx page:

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

.aspx.cs Page:

divSearch.enable = false; OR divSearch.enable = true;
Kamrul Hasan
  • 127
  • 1
  • 12
  • hi, i did as you said but when i go to the .cs page and put the divsearch.enable = false it says "divsearch is not declared it may be inaccessible due to its protection level" – Hala mahala Mar 22 '17 at 10:17
  • could it be because my aspx.designer.vb is not updating anymore?if its because of that im done xD – Hala mahala Mar 22 '17 at 10:19
  • are you use vb, I write code c#. I think you can do it in vb. please try. – Kamrul Hasan Mar 23 '17 at 05:11
  • the code in vb is the same but without the ";" at the end but my problem is that the designer file stopped updating a while ago and i have to be updating it manually every time i put a new control xD but the thing is i dont know how to update the designer based on a div. :\ – Hala mahala Mar 23 '17 at 10:10
  • i made another question a while back asking if anyone knew how to force it to update but no one answered :| and all the tutorials i see on the web are from vs 2003 - 2005 and im using the 2015 so y never lucky :P – Hala mahala Mar 23 '17 at 10:12