Using ASP.NET Input Validation on a Navigation List

In this topic, you’ll use a RequiredFieldValidator component with the C1NavigationList control. A RequiredFieldValidator component will evaluate the value of a C1NavigationListInputItem to ensure that users enter a value (in this case, a name) before being allowed to access the child item of a C1NavigationListItem.

Complete the following steps:

1.   In Design view, add a C1NavigationList control to your Web site project.

2.   Click the C1NavigationList control’s smart tag to open the C1NavigationList Tasks menu; select Edit NavigationList.

3.   Add a List Item and an Input Item to the control (see Adding Navigation List Items to the C1NavigationList Control).

4.   Select ListItem01, click the drop-down arrow next to the  Add Child Item button, and select Text Item from the list.

TextItem01 is added as a child item of ListItem01.

5.   In the treeview, select ListItem01 and set the following properties:

      Set the Text property to “CLICK ME”.

      Set the ValidationGroup property to “NameValidation”. This property specifies the group of controls that is validated upon a validation check.

6.   In the treeview, select Input01 and set the following properties:

      Set the Text property to “Name:”

      Set the WaterMarkText property to “Enter your name.”.

      Set the ID property to “NameInput”.

7.   In the treeview, select TextItem01 and set its ID property to  “NameText”.

If you switch to Source view, the markup will resemble the following:

Markup:

8.   Switch to Code view and add the following code to the Page_Load event:

      Visual Basic

      C#

9.   Press F5 to run the program. Observe that the C1NavigationList control has two top-level items: a list control that says “Click me” and an input control that says “Name: Enter your name.”

 

 

10.  Click the CLICK ME input item. Observe that you can’t access the list item’s child item and that the RequiredFieldValidator component displays “You must enter your name before proceeding.”

 

 

11.  Enter your name in the Name field.

12.  Click the CLICK ME input item again. Observe that the C1NavigationList control switches pages and shows a text item, which displays a message featuring your name.

 


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.