0

May you please help me on this: I developed a web application that has Checkboxes and i want to show some controls when the user tick the box and hide them when the user untick the box. I only managed to do the showing part when the user tick the box, now i'm failing to hide them when the user untick the box.

Here is the showing part of the my code:

 protected void chkboxMentor_CheckedChanged(object sender, EventArgs e)
    {
        lblMentorName.Visible = true;
        txtMentorName.Visible = true;
        lblMentorStuff.Visible = true;
        txtMentorStaffNo.Visible = true;
        lblMentorDate.Visible = true;
        btnShowCal.Visible = true;
    }

Please help me with the hiding part.

Any help please!!! It will be highly appreciated

4 Answers 4

1

You need to set the Visible property to the checkbox's Checked property.

Sign up to request clarification or add additional context in comments.

1 Comment

Guys, your answers are all relevant. Thank you
1
        lblMentorName.Visible = chkBoxMentor.Checked;
        txtMentorName.Visible = chkBoxMentor.Checked;
        lblMentorStuff.Visible = chkBoxMentor.Checked;
        txtMentorStaffNo.Visible = chkBoxMentor.Checked;
        lblMentorDate.Visible = chkBoxMentor.Checked;
        btnShowCal.Visible = chkBoxMentor.Checked;

EDIT: More elegant solution would be to put these controls in a Panel and just set the Visible property of that using the checkbox's Checked property

1 Comment

I'm not sure this is right, the OP wanted visibility toggled based on check box status not the label visibility
0

As SLaks says

just set

<Yourontrolname>.Visible = chkboxMentor.checked

for each control you wish to toggle

Comments

0
protected void chkboxMentor_CheckedChanged(object sender, EventArgs e) 
{ 
     if(chkboxMentor.Checked)
    {
        lblMentorName.Visible = true;
        txtMentorName.Visible = true; 
        lblMentorStuff.Visible = true;
        txtMentorStaffNo.Visible = true;
        lblMentorDate.Visible = true;
        btnShowCal.Visible = true; 
    }
    else
    {

        lblMentorName.Visible = false;
        txtMentorName.Visible = false; 
        lblMentorStuff.Visible = false;
        txtMentorStaffNo.Visible = false;
        lblMentorDate.Visible = false;
        btnShowCal.Visible = false; 
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.