0

I need to disable a form fields, using c# and asp.net

For example in this image Imag example

There's a checkbox, which when clicked it has to disable all fields, and user can click 'Guardar' to keep going with the registration.

Now, my question is, how can i do this in asp.net with c# and .NET framework 4.0?

Is there some tutorial or example i can use for this case?

If you need some code i can Edit my question.

Thanks in advance!

EDIT

I have these fields:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<div class="fixed-width-wrapper contentContainer">

<div style="padding:20px">
  <div style="padding-bottom:5px; border-bottom:solid 1px #cccccc; background-image:url('images/menuzulcon4.png'); height: 52px; width: 952px;" class="titulosGeneral";></div>
  <div class="curriculumdivcompleto">
  <div class="curriculumLadoRegistroizq">
    <div style="margin-top:10px" class="autenticacionTitulo">Nombre de la última o actual empresa</div>
    <div style="margin-top:5px"><asp:TextBox ID="nom_act_emp" runat="server" MaxLength="100" ValidationGroup="Curriculum" CssClass="autenticacionTextBox"></asp:TextBox></div>
  </div>
  <div class="curriculumLadoRegistro2">
    <div style="margin-top:10px" class="autenticacionTitulo">Dirección</div>
    <div style="margin-top:5px"><asp:TextBox ID="Direcc_emp" runat="server" MaxLength="100" ValidationGroup="Curriculum" CssClass="autenticacionTextBox"></asp:TextBox></div>
  </div>
  <div class="curriculumLadoRegistroizq">
    <div style="margin-top:10px" class="autenticacionTitulo">Teléfono</div>
    <div style="margin-top:5px"><asp:TextBox ID="Tel_emp" runat="server" MaxLength="100" ValidationGroup="Curriculum" CssClass="autenticacionTextBox"></asp:TextBox></div>
  </div>
  <div class="curriculumLadoRegistro2">
    <div style="margin-top:10px" class="autenticacionTitulo">Nombre y cargo de su jefe inmediato</div>
    <div style="margin-top:5px"><asp:TextBox ID="Jefe_emp" runat="server" MaxLength="100" ValidationGroup="Curriculum" CssClass="autenticacionTextBox"></asp:TextBox></div>
  </div></div></asp:Content>

I'll add the checkbox on top of them, and if i click it, it will disable them.

NeoVe
  • 3,767
  • 7
  • 45
  • 113
  • Hi, you might want to have a look at. http://stackoverflow.com/questions/505353/how-do-i-disable-all-controls-in-asp-net-page. However i'd go with the 2nd answer not the one marked as correct and see if that works for what you need first. – Mayhem50 Oct 14 '13 at 03:06

1 Answers1

1

Well, if you're using ASP.NET Webforms, you can fire an event attached to the CheckBox on the click. When you click in the checkbox, the operation have to disable all elements on the form (I think these elements are all into a form):

foreach (Control control in yourFormID.Controls)
{
    control.Enabled = false;
}

Or using Attributes:

foreach (Control control in yourFormID.Controls)
{
    control.Attributes["disabled"] = "disabled"; 
    // or...
    control.Attributes.Add("disabled", "disabled");
}

Or maybe use Javascript to it. More efficient than call the server to do this operation, in my opinion:

var form = document.getElementById('<%= yourFormID.ClientID %>');
form.disabled = true;

Hope it helps!

Kiwanax
  • 1,197
  • 1
  • 20
  • 37
  • Looks good, thank you very much :) i've edited my question anyways, adding some code just in case, just need to be sure what i'm stepping :), thank you. – NeoVe Oct 14 '13 at 03:47
  • I'll try your method tomorrow and let you know, thanks again! – NeoVe Oct 14 '13 at 04:09
  • This is how i wrote it @Kiwanax 'protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { foreach (Control TextBox in EnvianosTuCurriculum.Controls) { TextBox.Enabled = false; } }' Not working, i'm no expert on asp but i think "controls" are the actual TextBoxes, RadioButtons, Checkboxes, etc, right? – NeoVe Oct 15 '13 at 04:06
  • @KristianKoci Yeah, "Controls" means every element who inherit from Control base class. It contains Forms, TextBoxes, DropDowns, etc. Try to put your form into a `asp:UpdatePanel` and, when you finish this procedure to disable the elements, call `Update()` from the UpdatePanel. I added another approach on the code, see it above. – Kiwanax Oct 15 '13 at 22:44