Creating a Navigation Control

IOTA^_^    

ASP.NET Developer's JumpStart
By Paul D. Sheriff, Ken Getz
Table of Contents
Chapter 21.  Creating User Controls


You may want to have the navigation list, shown on the left in Figure 21.3, on more than just the main page in your application. You might want to display the list of links on the left, with content filling the rest of the page.

To accomplish this goal, you might create a table on each page, with the navigation information in the first column and the rest of the content filling the second column of the table. In addition, it seems like a user control would be the simplest way to use the same set of links on all the pages of your application.

In this section, you'll create a new user control containing all the links from Main.aspx and then modify Main.aspx to take advantage of the new user control. Along the way, you'll see how to create a simple table on a page.

Follow these steps to create your user control:

  1. Open Main.aspx in the page designer.

  2. Select all the links on the page, including the Label control separating the two groups of links.

    TIP

    To select all the links, you may find it easiest to click the page at the lower-right corner of the links and then drag up to the upper-left corner until all the links are selected.

  3. Press Ctrl+X to cut the controls to the Windows Clipboard.

  4. Select the Project, Add Web User Control menu item. Name the new user control NWLeftNav.ascx. Click Open.

  5. With the new user control open in the page designer, press Ctrl+V to paste the controls onto the new control.

  6. In the Solution Explorer window, right-click Main.aspx and select View Code from the context menu.

  7. Select the Page_Load and lnkLogout_Click procedures and press Ctrl+X to cut the procedures to the Clipboard.

  8. In the Solution Explorer window, right-click NWLeftNav.ascx and select View Code from the context menu.

  9. In the code window, select and delete the existing Page_Load procedure and then click Ctrl+V to paste the code you cut from Main.aspx.

  10. Save the project and close all the designer windows.

Now that you've created the navigation control, add it to Main.aspx:

  1. Load Main.aspx in the page designer.

  2. Click the page, immediately below the existing NWHeader user control.

  3. Select the Table, Insert, Table menu item.

  4. On the Insert Table dialog box, set the BorderSize property to 0, the Rows property to 1, and the Columns property to 2. Click OK to insert the new table.

  5. From the Solution Explorer window, click and drag NWLeftNav.ascx into the left column of the table.

  6. Run the project and verify that Main.aspx looks and works just as it did before you added the user controls.

TIP

You added the navigation user control to a table in this exercise. Why bother? If you want to use the navigation control on the same page as normal content, you'll often want to use the second column of the table to display the rest of the content for the page. This way, no content on the page will "wrap" into the area where the navigation list displays, and the columns of the table can stretch as far, vertically, as necessary.



    IOTA^_^    
    Top


    ASP. NET Developer's JumpStart
    ASP.NET Developers JumpStart
    ISBN: 0672323575
    EAN: 2147483647
    Year: 2002
    Pages: 234

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net