Wednesday, 20 July 2011

Using a Panel Control to Hide Content in C#


In this tutorial we will learn how to place the content of our web page into a container using the panel control.

The panel control can be used to display or hide all of the contents in the group at once as opposed to hiding one item at a time. The code presented in this tutorial is in C#.

We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!

Creating and Using the Panel Control to Hide Content
  1. Open Visual Studio 2010 or Visual Studio 2010 Web Developer Express and create a new web form and label it Containers. Make sure the Place Code in Separate File box is checked.
  2. Switch to design view and in the Toolbox under the standard menu, drag a checkbox control onto the page.
  3. In the properties panel change the text of the checkbox to Show Calendar and set the AutoPostBack property to True.
  4. In the toolbox under the standard menu, drag aPanel control onto the page in design view and make sure it is underneath the checkbox.
  5. In the properties panel, set the visible property of the panel to False. Setting the visible property to false prevents the browser from displaying the panel when the page first loads.
  6. In the Toolboxunder the standard menu, click and drag a calendar onto the page. Make sure you drag the calendar inside the panel on the page and then switch to source view. The source code should look like the code below.
  7. Switch back to design view and double click the checkbox control. This will take you to the code behind for the checkbox control.
  8. Insert the following code to create an event handler for the checkbox:
    Panel1.Visible = CheckBox1.Checked;
  9. Save the project and the run or debug your application. When the browser loads, you should see a checkbox that says "Show Calendar". Check the box to make the calendar visible. You can also uncheck the box again to make the calendar disappear.

No comments:

Post a Comment