Introduction

Vast Domains Incorporated ValidatedControls©

ValidatedControls© Version 4.1

Web Form Data Input Controls for .NET

Next

Chapter 1: Introduction

Most database related web applications support data input via web forms. Web forms utilize controls that are designed to accommodate a variety of data types and methods of input including normal text, text lists, decimal numbers, whole numbers, dates and booleans.

1.1 What are the ValidatedControls©?

The ValidatedControls are a set of aggregate server controls designed to be used in .NET web forms. The basic concept behind the ValidatedControls is to extend basic .NET form controls by imbedding appropriate validators, constraints, units of measurement, list values, ranges, text descriptors and error messages. The extensions are controlled and maintained by properties and attributes defined in a database table. The ValidatedControls are used with the ValidatedDataSet, an extended Data Set designed specifically for the ValidatedControls. Databinding for the ValidatedControls is accomplished using the ValidatedDataBinder.

1.2 ValidatedControls© Features

The ValidatedControls contain numerus features and are designed to handle most type of data that are entered and stored in today's databases. The major advantage of the ValidatedControls is in the minimization of required code behind and initial development time. Significant long-term advantages are gained in the reduction of maintenance, application changes and support time. Most application changes (i.e. data structure changes, range changes etc.) can be addressed by simple modifications to the back-end database with very minor changes to the front-end user interface code and web pages. This approach also minimizes the risks of detrimental side-effects from changes in other areas of the application. The ValidatedControls are simple to use and can be included in norma ASP.NET applications and DotNetNuke© applications.

Copyright 1998-2008 Vast Domains Incorporated


Installation

Chapter 2: Installation

Next

Back

2.1 Copy the ValidatedControls.DLL to the Bin Folder

The ValidatedControls.dll file must be placed in the Bin subdirectory of you web project. This can be done by a simple copy process.

2.2 Create the Structure and Lookup Database Tables

The Structure table is used to maintain the data structure definition. There is one row for each table/column in your database. This table is used to define the field description, user rights, units, type, size, help text, error text and range checks. The ValidatedControls use this information to control the behavior of the underlying data input controls. For more information on creating and populating the Structure table, see Setting Up the Structure and Lookup Tables. The Lookup table is used to maintain list values for both ValidatedDropDownList and ValidatedComboBox controls. For more information on creating and populating the Lookup table, see Setting Up the Structure and Lookup Tables.

2.3 Create the Lookup Database Table

The Lookup table is used in conjunction with ValidatedDropDownList and ValidatedComboBox controls. This table maintains the default list of values that are displayed in the dropdown for the ValidatedDropDownList and ValidatedComboBox. For more information on creating and populating the Lookup table, see Setting Up the Structure and Lookup Tables.

2.4 Create Stored Procedures

The following Stored Procedures are used in conjunction with the ValidatedControls© and must be added to the database:

  • Get_LookupData

  • Get_StructureItem

  • Get_StructureItems

Note: The scripts shown for creating tables and stored procedures are based upon the Microsoft SQL Server database. The ValidatedControls can be used with other back-end databases, however, the scripts must be modified for the selected database syntax.

2.5 Create/Populate Special Dropdown List and ComboBox List Tables (optional)

Special tables (in addition to the default Lookup table) can be set up to populate ValidatedDropDownList and ValidatedComboBox controls. When using user defined source tables, the following Stored Procedures must be modified and added to the database:

  • Get_SourceRow

  • Get_SourceKey

  • Get_SourceValue

2.6 XSD Directory

The ValidatedControls use a scratch directory to maintain table information retrieved from the database. This information is written to a directory that must be name XSD and must be under the root of the application.

2.7 Changes to web.config

2.7.1 Connection Setting

The following line must be added to the web.config file under the appSettings sections:

<add key="ConnectionString" value="server=YourServer;database=YourDatabase;uid=YourUser;Pwd=YourPassword;" />

2.7.2 Logger Setup

First enter the following line under the configSections area:

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />

Second, add the following complete section to enable error logging:

<log4net>

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">

<param name="File" value="Your path info.. i.e. c:\inetpub\wwwroot\test" />

<param name="AppendToFile" value="true" />

<param name="MaxSizeRollBackups" value="10" />

<param name="MaximumFileSize" value="5MB" />

<!-- Rolling Style = "Size", "Date", "Composite" (Size & Date) -->

<param name="RollingStyle" value="Composite" />

<param name="StaticLogFileName" value="true" />

<layout type="log4net.Layout.PatternLayout,log4net">

<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />

</layout>

</appender>

<appender name="HttpTraceAppender" type="log4net.Appender.ASPNetTraceAppender">

<layout type="log4net.Layout.PatternLayout">

<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />

</layout>

</appender>

<!-- Setup the root category, add the appenders and set the default priority -->

<root>

<level value="DEBUG" />

<appender-ref ref="RollingLogFileAppender" />

<appender-ref ref="HttpTraceAppender" />

</root>

</log4net>

Third, copy the log4net.dll to the Bin subdirectory of you web project.


Setting Up the Structure and Lookup Tables

Chapter 10: Setting Up the Structure Table and Lookup Tables

To create the Structure table, run the create Structure table script in your database. An example of the Structure table contents are shown below:

ID | Table Name | Field Name | Description | Selector | Rightsmask | Units | Type | Mask | Size | Help Text | Error Text | New Value | Required | Editable | Lowrange | Highrange | UseKey | Source Table | Source field
1 | VD_People | Weight | Weight | NULL | NULL | pounds | Integer | NULL | NULL | Enter this persons weight. | An individual weight is usually between 1 and 350 pounds. | FALSE | FALSE | TRUE | 5 | 350 | FALSE | NULL | NULL
2 | VD_People | Hair | Hair | NULL | NULL | NULL | Text | NULL | 10 | Select the individuals hair color. |  | FALSE | FALSE | TRUE | NULL | NULL | FALSE | NULL | NULL
3 | VD_People | Eyes | Eyes | NULL | NULL | NULL | Text | NULL | 10 | Select the individuals eye color. |  | FALSE | FALSE | TRUE | NULL | NULL | FALSE | NULL | NULL
4 | VD_People | Birthdate | Birthday | NULL | NULL | NULL | Date | NULL | NULL | Enter the individuals birth date. |  | FALSE | FALSE | TRUE | NULL | NULL | FALSE | NULL | NULL
5 | VD_People | Status | Marital status | NULL | NULL | NULL | Y/N | NULL | NULL | Check if this individual is married |  | FALSE | FALSE | TRUE | NULL | NULL | FALSE | NULL | NULL
6 | VD_People | City | City | NULL | NULL | NULL | Text | NULL | 10 | Enter the individuals city of residence |  | FALSE | FALSE | TRUE | NULL | NULL | FALSE | NULL | NULL
7 | VD_People | State | State | NULL | NULL | NULL | Text | NULL | 10 | Enter the individuals state of residence |  | FALSE | FALSE | TRUE | NULL | NULL | FALSE | NULL | NULL
8 | VD_People | First Name | First Name | NULL | NULL | NULL | Text | NULL | 10 | Enter the individuals Last Name |  | FALSE | FALSE | TRUE | NULL | NULL | FALSE | NULL | NULL
9 | VD_People | Last Name | Last Name | NULL | NULL | NULL | Text | NULL | 10 | Enter the individuals Last Name |  | FALSE | FALSE | TRUE | NULL | NULL | FALSE | NULL | NULL
10 | VD_People | Notes | Special Notes | NULL | NULL | NULL | Text | NULL | 1024 | Enter any special notes about this individual |  | FALSE | FALSE | TRUE | NULL | NULL | FALSE | NULL | NULL
11 | VD_People | Height | Height | NULL | NULL | ft-in | Text | NULL | 10 | Enter this persons height |  | FALSE | FALSE | TRUE | NULL | NULL | FALSE | NULL | NULL

The fields for the Structure table are defined as:

ID - Primary key field in the Lookup table

Table Name - Primary key of the field as defined in the Structure table (the ID of this field in the Structure table).

Field Name - The dropdown list value.

Description - A text field that can be used as a filter value at runtime to further limit the list of values displayed in the dropdown.

Selector - A generic text field that can be used to control applicability at runtime.

Rightsmask - An integer value that is used with role based security to further restrict control applicability.

Units - A text field that displays the units of measurement for the field.

Type - The field type: Text, Integer, Double, Date or Currency.

Mask - This field is currently unused.

Size - The maximum length of a Text type field.

Help Text - The Help text displayed when the user locates the cursor over the field on the form.

Error Text - The error text displayed when an improper value is entered for a field.

New Value - A boolean indicating if a new value can be specified for a field. This can be used to control if a ValidatedDropDownList or ValidatedComboBox is used at runtime.

Required - A boolean indicating if an input is required for a field.

Editable - A boolean indicating if the field is editable. Usually used during runtime in conjunction with the Rightsmask.

Lowrange - The acceptable low range for the value specified in a ValidatedTextBox.

Highrange - The acceptable high range for the value specified in a ValidatedTextBox.

UseKey - A boolean that indicates that the lookup values for a ValidatedDropDownList or ValidatedComboBox should be looked up using the primary key in the Source Table. This is used when a primary key (integer) is stored in the database row as opposed to the actual text list value.

Source Table - Table name of a user defined lookup table for a ValidatedDropDownList or ValidatedComboBox.

Source Field - Field name used for the lookup value in a user defined lookup Source Table for a ValidatedDropDownList or ValidatedComboBox.

To create the Lookup table, run the create Lookup table script in your database. An example of the Lookup table contents for a ValidatedDropDownList is shown below (this is an example for Hair color, ID = 2, as shown in the Structure table above):

ID | STRUCT ID | VALUE | TYPE
7 | 2 | Black | NULL
8 | 2 | Brown | NULL
9 | 2 | Red | NULL
10 | 2 | Blonde | NULL

The fields for the Lookup table are defined as:

ID - Primary key field in the Lookup table

STRUCT ID - Primary key of the field as defined in the Structure table (the ID of this field in the Structure table).

VALUE - The dropdown list value.

TYPE - A text field that can be used as a filter value at runtime to further limit the list of values displayed in the dropdown.

The Structure and Lookup tables use Stored Procedures to extract data at runtime. For more information see Required Stored Procedures.


ValidatedTextBox

Chapter 4: ValidatedTextBox

The ValidatedTextBox is an extended text box that is designed to accommodate the entry of most data entered in a database table. The appearance and functionality of the ValidatedTextBox included on a web form is based upon the Type of data the ValidatedTextBox is used for. The Type is specified in the Structure table. The ValidatedTextBox can be use with the following Types:

  • Text

  • Integer

  • Date

  • Double

  • Currency

The validators and rules applied to the control are dependent upon the Type specified in the Structure table and are described in the following:

4.1 Text Type

The ValidatedTextBox, when used with the Text type specified, displays a normal text box with limiting the length of the text entered to the Size specified in the Structure table. If the Required flag is set to True in the Structure table for this field, an additional required validator will be created in the form for this control forcing a legal entry in the text box and the text will be displayed next the text box.

4.2 Integer Type

The ValidatedTextBox, when used with the Integer type specified, displays a normal text box forcing the entry of integer numbers. Specifying the Highrange and Lowrange values in the Structure table will incorporate a range validator for this control. If the Required flag is set to True in the Structure table for this field, an additional required validator will be created in the form for this control forcing a legal entry in the text box and the text will be displayed next the text box.

4.3 Date Type

The ValidatedTextBox, when used with the Date type specified, displays a normal text box forcing the entry of legal date values in the format MM/DD/YYYY, MM/DD/YY, MM-DD-YYYY and MM-DD-YY. A popup calendar picker icon will be displayed next to the text box and can be used to select a date. If the Required flag is set to True in the Structure table for this field, an additional required validator will be created in the form for this control forcing a legal entry in the text box and the text will be displayed next the text box.

4.4 Double Type

The ValidatedTextBox, when used with the Double type specified, displays a normal text box forcing the entry of decimal numbers. Specifying the Highrange and Lowrange values in the Structure table will incorporate a range validator for this control. If the Required flag is set to True in the Structure table for this field, an additional required validator will be created in the form for this control forcing a legal entry in the text box and the text will be displayed next the text box.

4.5 Currency Type

The ValidatedTextBox, when used with the Currency type specified, displays a normal text box forcing the entry of legal currency values. Specifying the Highrange and Lowrange values in the Structure table will incorporate a range validator for this control. If the Required flag is set to True in the Structure table for this field, an additional required validator will be created in the form for this control forcing a legal entry in the text box and the text will be displayed next the text box.

4.6 Public Properties

The properties of this control include the normal properties exposed by the TextBox server control. In addition to those attributes, the following properties specific to the ValidatedTextBox apply and/or are additional attributes of properties inherited from the underlying TextBox control:

4.6.1 ItemID

Gets an integer that property that is the Primary Key (ID) in Structure table for this field.

4.6.2 TableName

Gets or sets the database the database table name that the ValidatedTextBox is being used for.

4.6.3 FieldName

Gets or sets the database field name within the TableName that the ValidatedTextBox is being used for.

4.6.4 Text

The string value displayed in the TextBox.

4.6.5 Columns

Gets or sets the display width of the TextBox in characters.

4.6.6 Rows

Gets or sets the number of rows displayed in a multiline text box.

4.6.7 TextMode

Gets or sets the behavior mode (single-line, multiline, or password) of the control.

4.6.8 Wrap

Gets or sets a value indicating whether the text content wraps within a multiline text box.

4.6.9 CssClass

Gets or sets the Style Sheet Class.

4.6.10 Description

Gets or sets a text string that describes the field and is displayed based upon the LabelAlign property setting.

4.6.11 LabelCss

Gets or sets the CSS class to be used for the label Description property text displayed when LabelAlign is set to Left or Right.

4.6.12 Rightsmask

Gets or sets an integer value that maps to a role that is used to limit the enables state of the control.

4.6.13 Units

Gets or sets the Units.

4.6.14 Type

Gets or sets the Type.

4.6.15 Mask

Gets or sets the regular Expression mask for RegularExpression Validator (currently not used).

4.6.16 Size

Gets or sets the text size.

4.6.17 HelpText

Gets or sets a text string displayed when the user places the cursor over the field.

4.6.18 ErrorText

Gets or sets a text string displayed when the user enters data that violates validations.

4.6.19 InternalToolTip

Gets or sets a boolean Indicating (True|False) whether to use internal or external javascript tooltips.

4.6.20 NewValue

Gets or sets a boolean that indicates if a new value is allowed.

4.6.21 Required

Gets or sets a boolean value indicating that a legal value must be entered for this control.

4.6.22 Editable

Gets or sets a boolean indicating if the control is editable.

4.6.23 Lowrange

Gets or sets a string that indicates the value low limit.

4.6.24 Highrange

Gets or sets a string that indicates the value high limit.

4.6.25 LabelAlign

Gets or sets a label alignment value (Left, Right or None). Specifying Left will display the Description text specified in the Structure table immediately to the left of the input text box. Specifying Right will display the Description text specified in the Structure table immediately to the right of the input text box. Specifying None will prevent the display of the Description text specified in the Structure table for this control.

4.6.26 Autobind

Gets or sets a direction value of Autobind with ValidatedDataBinder : Both|In|Out|None.

4.6.27 ParentEnableID

Set the control ID of the parent ValidatedCheckBox that is used to toggle the visibility of this ValidatedDropDownList when AJAX is used.

4.6.28 EnableMode

Used to specify enable/disable mode for AJAX client side enable : Hide | Disable | None.

4.7 Usage Example

The following is an example of the specification of this control in an .ASPX file:

First, include the following directive in the top section of your .ASPX file:

<%@ Register TagPrefix="vc" Namespace="ValidatedControls" Assembly="ValidatedControls" %>

Include ValidatedTextBox tags as needed within the body of the .ASPX (.ASCX) page:

<vc:ValidatedTextBox
 ID="vtFirstName" FieldName="First Name"
 TableName="VD_People" LabelAlign="Left" LabelCss="Normal"
  Runat="server" />

If ValidatedTextBox(es) are being used for the Date type; the following two lines must be included in the Page_Load event:

Page.ClientScript.RegisterClientScriptInclude("Calendar", ResolveUrl("~/js/Calendar.js"));

Page.ClientScript.RegisterClientScriptInclude("CalendarPopup", ResolveUrl("~/js/CalendarPopup.js"));

The Calendar.js and CalendarPopup.js javascript files (included with the ValidatedControls) must be included in the project. In the above example, these script files were copied to a "js" subdirectory located under the project root. They can therefore be referenced as "~/js/filename". The calendar icon file, SmallCalendar.gif, must be added to the images directory located under the root directory of the application.

In the code behind for the page; create a ValidatedDataSet and ValidatedDataBinder for the controls in the Page_Load event:

protected void Page_Load(Object Src, EventArgs E)

{

if (!IsPostBack)

{

string strSelect = "select * from [VD_People] where ID = " + ViewState["key"];

ValidatedDataSet vds = new ValidatedDataSet(strSelect, "VD_People");

Session["VCDataSet"] = vds;

bindingManager = new ValidatedDataBinder(vds);

bindingManager.BindTo(this);

}

}

The ViewState["key"] is the primary key for the record being retrieved and edited. This value can come in via the query string. To Save the data enter in the ValidatedControls, add an ASP button control on the page and put the following code in the OnClick event handler:

ValidatedDataSet vds = (ValidatedDataSet)Session["VCDataSet"];

bindingManager = new ValidatedDataBinder(vds);

if ( !bindingManager.BindFrom(this)) return false;

vds.UpdateDatabase();

To use the ValidatedControls with AJAX, the vcAjaxService.aspx and vcAjaxService.aspx.cs files must be in the root directory of the web application. These are the web service files that handle the async postback for the controls.


ValidatedDropDownList

Chapter 5: ValidatedDropDownList

The ValidatedDropDownList is an extended ListBox control. The values displayed in the list are contained in database table. This list of values displayed can be filtered at runtime and can be controlled by the values specified for other ValidatedControls on the page.

5.1 Public Properties

The properties of this control include the normal properties exposed by the underlying ListBox server control. The properties shown below are additional properties specific to the ValidatedDropDownList and/or describe additional attributes of the inherited ListBox control:

5.1.1 ItemID

Gets an integer that property that is the Primary Key (ID) in Structure table for this field.

5.1.2 TableName

Gets or sets the database the database table name that the control is being used for.

5.1.3 FieldName

Gets or sets the database field name within the TableName that the control is being used for.

5.1.4 SelectedValue

Gets or sets the value of the selected item in the list control.

5.1.4 SelectedIndex

Gets or sets the index of the selected value in the list control.

5.1.5 Rightsmask

A integer value that maps to a role that is used to limit the enables state of the control.

5.1.6 HelpText

Gets or sets a text string displayed when the user places the cursor over the field.

5.1.7 ErrorText

Gets or sets a text string displayed when the user enters data that violates validations.

5.1.8 NewValue

Gets or sets a boolean that indicates if a new value is allowed.

5.1.9 Required

Gets or sets a boolean value indicating that a legal value must be entered for this control.

5.1.10 Editable

Gets or sets a boolean indicating if the control is editable.

5.1.11 LabelAlign

Gets or sets a label alignment value (Left, Right or None). Specifying Left will display the Description text specified in the Structure table immediately to the left of the input text box. Specifying Right will display the Description text specified in the Structure table immediately to the right of the input text box. Specifying None will prevent the display of the Description text specified in the Structure table for this control.

5.1.12 Autobind

Gets or sets a direction value of Autobind with ValidatedDataBinder : Both|In|Out|None.

5.1.13 ParentControlID

Optional ID of the parent DropDownList (upon which the contents of this control are based).

5.1.14 ParentEnableID

Set the control ID of the parent ValidatedCheckBox that is used to toggle the visibility of this ValidatedDropDownList when AJAX is used.

5.1.15 EnableMode

Used to specify enable/disable mode for AJAX client side enable : Hide | Disable | None.

5.1.16 ParentValue

Gets or set the value of the radio button in the button list used to enable/disable control.

5.1.17 ServiceURL

URL of Ajax dataservice for validated control.

5.1.18 SourceTable

The user defined table used to populate the dropdownlist in the user defined SourceTable. By default, the ValidatedDropDownList used the Lookup table to populate the dropdownlist. Use of the SourceTable and SourceField attributes is optional.

5.1.19 SourceField

The user defined field used to populate the dropdownlist in the user defined SourceTable. By default, the ValidatedDropDownList used the Lookup table to populate the dropdownlist. Use of the SourceTable and SourceField attributes is optional.

5.1.20 SourceFilter

A SQL type where condition specified in the code behind that is used top populate the dropdownlist values. An example: "([Type] = 'North American' Or [Type] is null )" The SourceFilter clause can contain a parameter (specified as "?") that us used at runtime and can be the value of another ValdiatedControl on the page. An example: "[Type] = ?" The parameter field is specified in the SourceFilterValue attribute.

5.1.21 SourceFilterValue

A value specified from a control on the page that is used in the SourceFilter attribute at runtime. For example,

5.1.22 UseKey

A boolean indicating if a key value (integer) is stored in the database row instead of the text value.

5.1.23 EmptyValue

A string value to be displayed as the selected value when the underlying database value is null.

5.1.23 RemoveList

Get or sets an ArrayList of values that are to be removed from the listbox.

5.2 Public Methods

5.2.1 void Populate()

The Populate method is used to populate the list of values based upon the currently specified values on the .ASPX page.

5.3 Usage Example

The following is an example of the specification of this control in an .ASPX file:

First, include the following directive in the top section of your .ASPX file:

<%@ Register TagPrefix="vc" Namespace="ValidatedControls" Assembly="ValidatedControls" %>

Include ValidatedDropDownList tags as needed within the body of the .ASPX (.ASCX) page:

<vc:ValidatedDropDownList ID="vdHair"
 FieldName="Hair" TableName="VD_People" LabelAlign="Left"
 LabelCss="Normal" Runat="server" />

This above example uses the Lookup table to populate the list of values in the dropdown list.

In the code behind for the page; create a ValidatedDataSet and ValidatedDataBinder for the controls in the Page_Load event:

protected void Page_Load(Object Src, EventArgs E)

{

if (!IsPostBack)

{

string strSelect = "select * from [VD_People] where ID = " + ViewState["key"];

ValidatedDataSet vds = new ValidatedDataSet(strSelect, "VD_People");

Session["VCDataSet"] = vds;

bindingManager = new ValidatedDataBinder(vds);

bindingManager.BindTo(this);

}

}

The ViewState["key"] is the primary key for the record being retrieved and edited. This value can come in via the query string. To Save the data enter in the ValidatedControls, add an ASP button control on the page and put the following code in the OnClick event handler:

ValidatedDataSet vds = (ValidatedDataSet)Session["VCDataSet"];

bindingManager = new ValidatedDataBinder(vds);

if ( !bindingManager.BindFrom(this)) return false;

vds.UpdateDatabase();

To use the ValidatedControls with AJAX, the vcAjaxService.aspx and vcAjaxService.aspx.cs files must be in the root directory of the web application. These are the web service files that handle the async postback for the controls.


ValidatedMultiSelect

Chapter 8: ValidatedMultiSelect

The ValidatedMultiSelect is an extended CheckBoxList in which the selectable values can be specified in the Lookup table. By default, the ValidatedMultiSelect stores data in a child database table that maintains the applicable list of selected values for each parent table data row. The child table name must be created be created by the developer and must be structured as follows:

Table Name: Parent Table Name + Parent Field Name

Example:

Parent Table: VD_People

Parent Field: AllApplicable Field Type: Text

Child Table Name: VD_People AllApplicable

Child Table Fields:

Field Name: [ID] [int] IDENTITY(1,1) NOT NULL

Field Name: [ParentID] [int] NULL

Field Name: [AllApplicable] [nvarchar](20) NOT NULL

Field Name: [Selected] [bit] NULL

The field ID, ParentID, and Selected must be specified and named as stated. The remaining field name is the same field name (and size) that appears in the parent table. In the above example, AllApplicable is a text field that appears in the parent table VD_People (this field can be set to any legal length).

8.1 Public Properties

The properties of this control include the normal properties exposed by the underlying CheckedListBox control. The properties shown below are additional properties specific to the ValidatedMultiSelect and/or describe additional attributes of the inherited CheckedListBox control:

8.1.1 ItemID

Gets an integer that property that is the Primary Key (ID) in Structure table for this field.

8.1.2 TableName

Gets or sets the database the database table name that the control is being used for.

8.1.3 FieldName

Gets or sets the database field name within the TableName that the control is being used for.

8.1.4 CssClass

Gets or sets the Style Sheet Class.

8.1.5 Description

Gets or sets a text string that describes the field and is displayed based upon the LabelAlign property setting.

8.1.6 LabelCss

Gets or sets the CSS class to be used for the label Description property text displayed when LabelAlign is set to Left or Right.

8.1.7 Rightsmask

Gets or sets an integer value that maps to a role that is used to limit the enables state of the control.

8.1.8 HelpText

Gets or sets a text string displayed when the user places the cursor over the field.

8.1.9 ErrorText

Gets or sets a text string displayed when the user enters data that violates validations.

8.1.10 InternalToolTip

Gets or sets a boolean Indicating (True|False) whether to use internal or external javascript tooltips.

8.1.11 LabelAlign

Gets or sets a label alignment value (Left, Right or None). Specifying Left will display the Description text specified in the Structure table immediately to the left of the input text box. Specifying Right will display the Description text specified in the Structure table immediately to the right of the input text box. Specifying None will prevent the display of the Description text specified in the Structure table for this control.

8.1.12 Autobind

Gets or sets a direction value of Autobind with ValidatedDataBinder : Both|In|Out|None.

8.1.13 Height

Sets or get the height of the control.

8.1.14 Width

Sets or gets the width of the control.

8.1.15 ParentEnableID

Set the control ID of the parent ValidatedCheckBox that is used to toggle the visibility of this ValidatedDropDownList when AJAX is used.

8.1.16 EnableMode

Used to specify enable/disable mode for AJAX client side enable : Hide | Disable | None.

8.1.17 ArrayList RemoveList

Get or sets an ArrayList of values that are to be removed from the listbox.

8.2 Public Methods

8.2.1 bool BindValues(int ParentId)

Binds the default to the ValidatedMultiSelect control. ParentId is the primary key of the row for the parent table.

8.2.2 bool BindValues(int ParentId, ValidatedDataSet vdsDataSet)

Binds the values in the incoming vdsDataSet to the ValidatedMultiSelect control. ParentId is the primary key of the row for the parent table.

8.2.3 bool StoreValues(int ParentId, ValidatedDataSet vdsDataSet)

Stores the current values specified in the ValidatedMultiSelect. ParentId is the primary key of the row for the parent table.

8.2.4 bool GetSelected(string descriptor)

Returns the current checkbox (True=Checked, False=Unchecked) state for the item in the list that matches the descriptor string.

8.2.5 void SetSelected(string descriptor, bool selected)

Set the checkbox state to selected for the item in the list that matches the descriptor string.

8.2.6 void ClearAllSelected()

Set all the values in the group to unchecked.

8.3 Usage Example

The following is an example of the specification of this control in an .ASPX file:

First, include the following directive in the top section of your .ASPX file:

<%@ Register TagPrefix="vc" Namespace="ValidatedControls" Assembly="ValidatedControls" %>

Include ValidatedMultiSelect tags as needed within the body of the .ASPX (.ASCX) page:

<vc:ValidatedMultiSelect id="vmsApplies"
 FieldName="AllApplicable" TableName="VD_People" LabelAlign="None"
 LabelCss="tn9" runat="server" Height="65"
 />

In the code behind for the page; create a ValidatedDataSet and ValidatedDataBinder for the controls in the Page_Load event:

protected void Page_Load(Object Src, EventArgs E)

{

if (!IsPostBack)

{

string strSelect = "select * from [VD_People] where ID = " + ViewState["key"];

ValidatedDataSet vds = new ValidatedDataSet(strSelect, "VD_People");

Session["VCDataSet"] = vds;

bindingManager = new ValidatedDataBinder(vds);

bindingManager.BindTo(this);

}

}

The ViewState["key"] is the primary key for the record being retrieved and edited. This value can come in via the query string. To Save the data enter in the ValidatedControls, add an ASP button control on the page and put the following code in the OnClick event handler:

ValidatedDataSet vds = (ValidatedDataSet)Session["VCDataSet"];

bindingManager = new ValidatedDataBinder(vds);

if ( !bindingManager.BindFrom(this)) return false;

vds.UpdateDatabase();


ValidatedLabel

Chapter 9: ValidatedLabel

The ValidatedLabel is an extended Label control that is designed to be used with other ValidatedControls. The visibility of this control can be based upon the status of a ValidatedCheckBox located elsewhere on the page.

9.1 Public Properties

The properties of this control include the normal properties exposed by the underlying Label server control. The properties shown below are additional properties specific to the ValidatedLabel:

9.1.1 ParentEnableId

The control ID of the parent ValidatedCheckBox that is used to toggle the visibility of this ValidatedLabel.

9.1.2 ParentValue

Gets or sets a string value of the radio button in the button list used to enable/disable control.

9.1.3 EnableMode

Used to specify enable/disable mode for AJAX client side enable : Hide | Disable | None.

9.2 Usage Example

The following is an example of the specification of this control in an .ASPX file:

First, include the following directive in the top section of your .ASPX file:

<%@ Register TagPrefix="vc" Namespace="ValidatedControls" Assembly="ValidatedControls" %>

Include ValidatedLabel tags as needed within the body of the .ASPX (.ASCX) page:

<vc:ValidatedLabel ID="vlName" Text="First Name" Runat="server" ParentEnableID="vchkStatus"/>

The control in the example above will only be visible when the vchkStatus ValidatedCheckBox on the page is checked.


ValidatedComboBox

Chapter 6: ValidatedComboBox

The ValidatedComboBox functions like a ValidatedDropDownList but adds an imbedded textbox that can be used to input values that are not displayed in the dropdownlist. For more information on specifying values for the dropdownlist, see the ValidatedDropDownList.

6.1 Usage Example

The following is an example of the specification of this control in an .ASPX file:

First, include the following directive in the top section of your .ASPX file:

<%@ Register TagPrefix="vc" Namespace="ValidatedControls" Assembly="ValidatedControls" %>

Include ValidatedDropDownList tags as needed within the body of the .ASPX (.ASCX) page:

<vc:ValidatedComboBox ID="vdEyeColor"
 FieldName="Hair" TableName="VD_People" LabelAlign="Left"
 LabelCss="Normal" Runat="server" />

This above example uses the Lookup table to populate the list of values in the dropdown list.

In the code behind for the page; create a ValidatedDataSet and ValidatedDataBinder for the controls in the Page_Load event:

protected void Page_Load(Object Src, EventArgs E)

{

if (!IsPostBack)

{

string strSelect = "select * from [VD_People] where ID = " + ViewState["key"];

ValidatedDataSet vds = new ValidatedDataSet(strSelect, "VD_People");

Session["VCDataSet"] = vds;

bindingManager = new ValidatedDataBinder(vds);

bindingManager.BindTo(this);

}

}

The ViewState["key"] is the primary key for the record being retrieved and edited. This value can come in via the query string. To Save the data enter in the ValidatedControls, add an ASP button control on the page and put the following code in the OnClick event handler:

ValidatedDataSet vds = (ValidatedDataSet)Session["VCDataSet"];

bindingManager = new ValidatedDataBinder(vds);

if ( !bindingManager.BindFrom(this)) return false;

vds.UpdateDatabase();


ValidatedCheckBox

Chapter 7: ValidatedCheckBox

The ValidatedCheckBox is an extended CheckBox that can be used to control the visibility of other ValidatedControls on the page.

7.1 Public Properties

The properties of this control include the normal properties exposed by the underlying CheckBox server control. The properties shown below are additional properties specific to the ValidatedCheckBox and/or describe additional attributes of the inherited CheckBox control:

The properties of this control include the normal properties exposed by the CheckBox server control. In addition to those attributes, the following properties specific to the ValidatedCheckBox apply and/or are additional attributes of properties inherited from the underlying CheckBox control:

7.1.1 ItemID

Gets an integer that property that is the Primary Key (ID) in Structure table for this field.

7.1.2 TableName

Gets or sets the database the database table name that the control is being used for.

7.1.3 FieldName

Gets or sets the database field name within the TableName that the control is being used for.

7.1.4 TextAlign

Gets or set a value that specifies the side that the caption appears on : Right|Left.

7.1.5 CssClass

Gets or sets the Style Sheet Class.

7.1.6 Description

Gets or sets a text string that describes the field and is displayed based upon the TextAlign property setting.

7.1.7 Rightsmask

Gets or sets an integer value that maps to a role that is used to limit the enables state of the control.

7.1.8 Checked

Gets or sets a value (True|False) indicating whether the CheckBox control is checked.

7.1.9 HelpText

Gets or sets a text string displayed when the user places the cursor over the field.

7.1.10 ErrorText

Gets or sets a text string displayed when the user enters data that violates validations.

7.1.11 InternalToolTip

Gets or sets a boolean Indicating (True|False) whether to use internal or external javascript tooltips.

7.1.12 Editable

Gets or sets a boolean indicating if the control is editable.

7.1.13 Autobind

Gets or sets a direction value of Autobind with ValidatedDataBinder : Both|In|Out|None.

7.2 Usage Example

The following is an example of the specification of this control in an .ASPX file:

First, include the following directive in the top section of your .ASPX file:

<%@ Register TagPrefix="vc" Namespace="ValidatedControls" Assembly="ValidatedControls" %>

Include ValidatedCheckBox tags as needed within the body of the .ASPX (.ASCX) page:

<vc:ValidatedCheckBox ID="vchkStatus"
 FieldName="Status" TableName="VD_People" CssClass="Normal"
 Runat="server" />

In the code behind for the page; create a ValidatedDataSet and ValidatedDataBinder for the controls in the Page_Load event:

protected void Page_Load(Object Src, EventArgs E)

{

if (!IsPostBack)

{

string strSelect = "select * from [VD_People] where ID = " + ViewState["key"];

ValidatedDataSet vds = new ValidatedDataSet(strSelect, "VD_People");

Session["VCDataSet"] = vds;

bindingManager = new ValidatedDataBinder(vds);

bindingManager.BindTo(this);

}

}

The ViewState["key"] is the primary key for the record being retrieved and edited. This value can come in via the query string. To Save the data enter in the ValidatedControls, add an ASP button control on the page and put the following code in the OnClick event handler:

ValidatedDataSet vds = (ValidatedDataSet)Session["VCDataSet"];

bindingManager = new ValidatedDataBinder(vds);

if ( !bindingManager.BindFrom(this)) return false;

vds.UpdateDatabase();


ValidatedDataSet

Chapter 11: ValidatedDataSet

The ValidatedDataSet is an extended .NET DataSet that is designed to be used with the ValidatedControls and ValidatedDataBinder.

11.1 Public Properties

11.1.1 DataSet

Gets/sets the underlying DataSet.

11.1.2 Adapter

Gets/sets the SqlDataAdapter for the DataSet.

11.1.3 Command

Gets/sets the SqlCommand for the DataSet.

11.1.4 Name

Gets or sets the name of the ValdiatedDataSet.

11.2 Constructors

11.2.1 ValidatedDataSet(string selectString, string tableName)

Constructs a ValidatedDataSet and adds the tableName to the table list and populates the table based upon the selectString .

11.2.2 ValidatedDataSet(string selectString, string tableName, string connectionString)

Constructs a ValidatedDataSet and adds the tableName to the table list and populates the table based upon the selectString using the connectionString provided.

11.2.3 ValidatedDataSet(string tableName, bool bAddRow, string connectionString)

Constructs a ValidatedDataSet and adds the tableName to the table list using the connectionString provided. Setting the bAddRow to true will add an empty DataRow for the tableName.

11.2.4 public ValidatedDataSet(string tableName, bool bAddRow)

Constructs a ValidatedDataSet and adds the tableName to the table list. Setting the bAddRow to true will add an empty DataRow for the tableName.

11.3 Public Methods

11.3.1 bool AddTable(string selectString, string tableName)

Add the table tableName to the ValidatedDataSet and populates it using the selectString.

11.3.2 bool AddTable(string tableName)

Add the table tableName to the ValidatedDataSet.

11.3.3 bool UpdateTable(string tableName)

Saves the data in the ValidatedDataSet for tableName to the database.

11.3.4 int getRowIndex(string tableName)

Returns the currently selected row index (int) for the tableName.

11.3.5 DataRow getRow(string tableName)

Returns a DataRow for the currently selected row for the tableName.

11.3.6 bool setRow(string tableName, int primaryKey)

Sets the currently selected row index (cursor position) for the tableName based upon the primaryKey.

11.3.7 int AddRow(string tableName)

Adds an empty DataRow to the tableName.

11.3.8 void UpdateForeignKey(string tableName, string fieldName, Object oldKey, Object newKey)

Updates a foreign key value in a child table tableName using the oldKey and fieldName in the lookup and replaces the oldKey with newKey.

11.3.9 DataView AddView(string selectString, string tableName, string viewName)

Add the DataView viewName and table tableName to the ValidatedDataSet and populates it using the selectString.

11.3.10 DataView GetView(string viewName)

Returns the DataView viewName from the ValidatedDataSet.

11.3.11 bool UpdateDatabase()

Saves the data in the ValidatedDataSet for ALL tables to the database.

11.4 Example Usage

The following snippet creates and new ValidatedDataSet for the table VD_People and adds a new empty row to the DataSet.

ValidatedDataSet vds = new ValidatedDataSet("VD_People", true);


ValidatedDataBinder

Chapter 12: ValidatedDataBinder

The ValidatedDataBinder is a binding class designed specifically to bind the ValidatedControls to the ValidatedDataSet.

12.1 Public Properties

12.1.1 Vds

Gets or sets the underlying ValidatedDataSet.

12.1.1 DataRow

Gets or set the current DataRow.

12.2 Constructors

12.2.1 ValidatedDataBinder()

Creates a ValidatedDataBinder instance.

12.2.2 ValidatedDataBinder(ValidatedDataSet vds)

Creates a ValidatedDataBinder instance and set the ValidatedDataSet property to vds.

12.3 Public Methods

12.3.1 void BindFormTo(Control htmlForm)

12.3.2 void BindTo(Page form)

12.4.3 void BindTo ( Control ctl )

12.4.4 void BindTo(UserControl panel)

12.4.5 bool BindFormFrom(System.Web.UI.HtmlControls.HtmlForm htmlForm)

12.4.6 bool BindFrom(Page form)

12.4.7 bool BindFrom(Control panel)

12.4 Example Usage

The following snippet creates and new ValidatedDataSet, adds the table VD_People and populates the table using the select string. The ValidatedControls on the page are bound to the DataRow values using the ValidatedDataBinder.

string strSelect = "select * from [VD_People] where ID = " + ViewState["key"];

ValidatedDataSet vds = new ValidatedDataSet(strSelect, "VD_People");

bindingManager = new ValidatedDataBinder(vds);

if ( !bindingManager.BindFrom(this) ) return false;


Required Stored Procedures

Get_LookupData Stored Procedure

USE [YourDatabase]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [Get_LookupData]

@StructureID int

AS

SELECT Value FROM Lookup WHERE [STRUCT ID] = @StructureID

ORDER BY Value

Get_StructureItem Stored Procedure

USE [YourDatabase]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

Create Procedure [dbo].[Get_StructureItem]

@TableName varchar(50),

@FieldName varchar(62)

AS

SELECT * FROM Structure WHERE [TABLE NAME] = @TableName AND [FIELD NAME] = @FieldName

Get_StructureItems Stored Procedure

USE [YourDatabase]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[Get_StructureItems]

@TableName varchar(50)

AS

SELECT * FROM Structure WHERE [TABLE NAME] = @TableName

Get_SourceRow Stored Procedure (Optional)

/**** Note: The procedure below must be modified to use your special lookup tables (YourTableA, YourTableB etc). The ***/

/**** WHERE clause uses the primary key for each table (YourTableA.PrimaryKeyFieldName) ***/

USE [YourDatabase]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[Get_SourceRow]

@tablename varchar(64),

@key int

AS

if @tablename = 'YourTableA'

SELECT * FROM YourTableA WHERE [YourTableA.PrimaryKeyFieldName] = @key

else if @tablename = YourTableB'

SELECT * FROM YourTableB WHERE [YourTableB.PrimaryKeyFieldName] = @key

.....

.....

Get_SourceKey Stored Procedure (Optional)

/**** Note: The procedure below must be modified to use your special lookup tables (YourTableA, YourTableB etc). The ***/

/**** WHERE clause uses a text field defined in your source lookup table; name is the field used in the example below ***/

USE [YourDatabase]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[Get_SourceKey]

@tablename varchar(64),

@fieldname varchar(64),

@value varchar(128)

AS

if @tablename = 'YourTableA'

SELECT * FROM YourTableA WHERE [name] = @value

else if @tablename = 'YourTableB'

SELECT * FROM YourTableB WHERE [name] = @value

....

....

Get_SourceValue Stored Procedure (Optional)

/**** Note: The procedure below must be modified to use your special lookup tables (YourTableA, YourTableB etc). The ***/

/**** lookup value uses a text field defined in your source lookup table; name is the field used in the example below. ***/

/*** The WHERE clause uses a text field defined in your source lookup table; name is the field used in the example below ***/

USE [YourDatabase]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[Get_SourceValue]

@tablename varchar(64),

@fieldname varchar(64),

@key int

AS

if @tablename = 'YourTableA'

SELECT [name] FROM YourTableA WHERE [YourTableA.PrimaryKeyFieldName] = @key

else if @tablename = 'YourTableB'

SELECT [name] FROM YourTableB WHERE [YourTableB.PrimaryKeyFieldName] = @key

....

....


Example 1: Simple ValidatedControls in ASP.NET

Example 1: ValidatedControls in ASP.NET

This example demonstrates the simple use of ValidatedControls in an .ASPX page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register TagPrefix="mbcbb" Namespace="MetaBuilders.WebControls" Assembly="MetaBuilders.WebControls.ComboBox" %>

<%@ Register TagPrefix="vc" Namespace="ValidatedControls" Assembly="ValidatedControls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Vast Domains Validated Controls</title>

<link href="local.css" type="text/css" rel="stylesheet" />

</head>

<body>

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server" />

<div>

<table cellpadding="2" cellspacing="6" border="0" class="Normal">

<tr>

<td colspan="2">

<vc:ValidatedTextBox ID="vtFirstName" FieldName="First Name" TableName="VD_People" Required="true"

LabelAlign="Left" LabelCss="Normal" Runat="server" />

</td>

<td colspan="2" >

<vc:ValidatedTextBox ID="vtLastName" FieldName="Last Name" TableName="VD_People"

LabelAlign="Left" LabelCss="Normal" Runat="server" />

</td>

<td colspan="2"></td>

</tr>

<tr>

<td colspan="2" >

<vc:ValidatedDropDownList ID="vdHair" FieldName="Hair" TableName="VD_People"

LabelAlign="Left" LabelCss="Normal" Runat="server" />

</td>

<td colspan="2" >

<vc:ValidatedComboBox ID="vdEyeColor" FieldName="Eyes" TableName="VD_People"

LabelAlign="Left" LabelCss="Normal" Runat="server" />

</td>

<td colspan="2">

<vc:ValidatedCheckBox ID="vchkStatus" FieldName="Status" TableName="VD_People"

CssClass="Normal" Runat="server" />

</td>

</tr>

<tr>

<td colspan="2">

<vc:ValidatedTextBox ID="vtHeight" FieldName="Height" TableName="VD_People"

LabelAlign="Left" LabelCss="Normal" Runat="server" />

</td>

<td colspan="2" >

<vc:ValidatedTextBox ID="vtWeight" FieldName="Weight" TableName="VD_People"

LabelAlign="Left" LabelCss="Normal" Runat="server" />

</td>

<td colspan="2" >

<vc:ValidatedTextBox ID="vtBirthday" FieldName="Birthdate" TableName="VD_People" ParentEnableID="vchkStatus"

LabelCss="Normal" LabelAlign="Left" Runat="server" />

</td>

</tr>

<tr>

<td colspan="6" >

<vc:ValidatedTextBox ID="vtNotes" FieldName="Notes" TableName="VD_People"

                            LabelAlign="Right"
LabelCss="Normal"  TextMode="MultiLine"
Rows="10" Columns="75" Wrap="true"  Runat="server"
 />

</td>

</tr>

</table>

           <asp:LinkButton
runat="server"  ID="lbtnFormUpdate"
CssClass="CommandButton" Text="Save" OnClick="lbtnFormUpdate_Click"
/>&nbsp;&nbsp;

           <asp:LinkButton
runat="server"  ID="lbtnFormCancelUpdate"
CausesValidation="False" CssClass="CommandButton"
Text="Cancel" OnClick="lbtnFormCancelUpdate_Click"
/>

</div>

</form>

</body>

</html>

The codebehind for this page is shown below:

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page

{

protected ValidatedControls.ValidatedDataBinder bindingManager;

protected void Page_Load(object sender, EventArgs e)

{

Page.ClientScript.RegisterClientScriptInclude("Calendar", ResolveUrl("~/js/Calendar.js"));

Page.ClientScript.RegisterClientScriptInclude("CalendarPopup", ResolveUrl("~/js/CalendarPopup.js"));

if (!IsPostBack)

{

string strSelect = "select * from [VD_People] where ID = 1";

ValidatedControls.ValidatedDataSet vds = new ValidatedControls.ValidatedDataSet(strSelect, "VD_People");

Session["VDDataSet"] = vds;

if (vds.DataSet.Tables["VD_People"].Rows.Count == 0)

{

// If no existing record is present, add one

DataTable tbl = vds.DataSet.Tables["VD_People"];

DataRow row = tbl.NewRow();

tbl.Rows.Add(row);

}

else

{

//Data row exists ..

DataRow row = vds.DataSet.Tables["VD_People"].Rows[0];

}

bindingManager = new ValidatedControls.ValidatedDataBinder(vds);

bindingManager.BindTo(this);

DataBind();

}

}

protected void cmdCancel_Click(System.Object sender, System.EventArgs e)

{

}

protected void lbtnFormCancelUpdate_Click(object sender, System.EventArgs e)

{

}

protected void lbtnFormUpdate_Click(object sender, System.EventArgs e)

{

SaveRow();

}

protected bool InsertPeople()

{

ValidatedControls.ValidatedDataSet vds = (ValidatedControls.ValidatedDataSet)Session["ActiveVDS"];

ValidatedControls.ValidatedDataBinder bindingManager = new ValidatedControls.ValidatedDataBinder(vds);

if (!bindingManager.BindFrom((Control)this)) return false;

vds.UpdateDatabase();

return true;

}

/// <summary>

/// Updates an existing record based upon the values in the FormView controls

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected bool UpdatePeople()

{

ValidatedControls.ValidatedDataSet vds = (ValidatedControls.ValidatedDataSet)Session["ActiveVDS"];

ValidatedControls.ValidatedDataBinder bindingManager = new ValidatedControls.ValidatedDataBinder(vds);

if (!bindingManager.BindFrom((Control)this)) return false;

DataRow row = vds.DataSet.Tables[0].Rows[0];

vds.UpdateDatabase();

return true;

}

protected void SaveRow()

{

ValidatedControls.ValidatedDataSet vds = (ValidatedControls.ValidatedDataSet)Session["ActiveVDS"];

DataRow row = vds.DataSet.Tables[0].Rows[0];

int _ID = -1;

if (!row.IsNull("ID")) _ID = Convert.ToInt32(row["ID"]);

if (_ID > 0)

UpdatePeople();

else

InsertPeople();

//Response.Redirect(yourpage);

}

}


Basic Concepts

Chapter 3: Basic Concepts

3.1 Control Concepts

The ValidatedControls consist of six controls each of which is designed for a specific data input function. Each of the controls is used by placing them in an .ASPX or .ASCX. The default properties of the control are defined in a database table named Structure. When a page is requested, the server-side code retrieves the properties and attributes of the control and adds/injects the validators, descriptions, error messages, list values and other dependencies needed for the outgoing client page. The Lookup table is used to maintain the default listbox items that are displayed in both the ValidatedDropDownList and ValidatedComboBox. The Structure and Lookup tables must be defined and populated in the database prior to using the ValidatedControls. For more information on the Structure and Lookup tables, see Setting Up the Structure and Lookup Tables. The ValidatedControls are used in conjunction with the ValidatedDataSet and a ValidatedDataBinder classes that further minimize the amount of codebehind needed to use the controls. The general procedure to use the ValidatedControls is simple:

  1. Place the ValidatedControls in the ASPX/ASCX page.

  2. Create a ValidatedDataSet

  3. Create a ValidatedDataBinder and bind the controls on the page.

  4. Retrieve the form entered data using the ValidatedDataBinder

  5. Save the data using the ValidatedDataSet

3.1.1 ValidatedTextBox

The ValidatedTextBox is an extended textbox that is designed to handle the input of text data, integer numbers, decimal numbers, currency and dates. The visibility of a ValidatedTextBox can be controlled by the value of a parent control used on the same page.

3.1.2 ValidatedDropDownList

The ValidatedDropDownList is an extended dropdownlist. The list values are specified in a database table. The actual list of values can be controlled at run-time by a simple filtering mechanism and can be dependent upon selected/specified values for other ValidatedControls on the page.

3.1.3 ValidatedComboBox

The ValidatedComboBox is designed to function similar to normal Windows from combobox. The ValidatedComboBox behaves like a ValidatedDropDownList but is extended to allow the entry of a new value (not in the list of values) via a textbox. The list values are specified in a database table and feature the same properties and attributes of the ValidatedDropDownList.

3.1.4 ValidatedCheckBox

The ValidatedCheckBox is an extended checkbox that can be used to control the visibility of other ValidatedControls used on the same page.

3.1.4 ValidatedMultiSelect

The ValidatedMultiSelect is an extended checkbox list control. This control displays a list of values with a each with a checkbox that can be selected/checked.

3.1.5 ValidatedLabel

The ValidatedLabel is an extended label control that is designed to used in conjunction with the other ValidatedControls. The visibility of the ValidatedLabel is controlled by a parent ValidatedCheckBox used on the same page.

3.1.6 ValidatedDataSet

The ValidatedDataSet is an extended .NET data set class that is designed to used in conjunction with the ValidatedControls.

3.1.7 ValidatedDataBinder

The ValidatedDataBinder is a binding class that is used to bind the data in ValidatedControls to the ValidatedDataSet.

To use the ValidatedControls with AJAX, the vcAjaxService.aspx and vcAjaxService.aspx.cs files must be in the root directory of the web application. These are the web service files that handle the async postback for the controls.


Create Lookup Table

Create Lookup Table Script

USE [YourDatabase]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_PADDING ON

GO

CREATE TABLE [dbo].[Lookup](

[ID] [int] IDENTITY(1,1) NOT NULL,

[STRUCT ID] [int] NULL,

[VALUE] [nvarchar](64) NULL,

[TYPE] [char](3) NULL,

CONSTRAINT [PK_Lookup] PRIMARY KEY CLUSTERED

(

[ID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

GO

SET ANSI_PADDING OFF


Examples

Chapter 13: Examples

There are two examples provided in this document. Both examples utilize the People table and data. The first example is provided to demonstrate the use of the ValidatedControls© in a normal ASP.NET application. The second example demonstrates the use of the ValidatedControls© in a DotNetNuke© project.

Example 1: Simple ValidatedControls© in ASP.NET


Example 2: ValidatedControls in DotNetNuke

The ValidatedControls can be included and used in DotNetNuke Modules.


Create Structure Table

Create Structure Table Script

USE [YourDatabase]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Structure](

[ID] [int] IDENTITY(1,1) NOT NULL,

[TABLE NAME] [nvarchar](50) NULL,

[FIELD NAME] [nvarchar](62) NOT NULL,

[DESCRIPTION] [nvarchar](128) NULL,

[SELECTOR] [nvarchar](4) NULL,

[RIGHTSMASK] [int] NULL,

[UNITS] [nvarchar](50) NULL,

[TYPE] [nvarchar](50) NULL,

[MASK] [nvarchar](50) NULL,

[SIZE] [int] NULL,

[HELP TEXT] [nvarchar](1000) NULL,

[ERROR TEXT] [nvarchar](1000) NULL,

[NEW VALUE] [bit] NOT NULL,

[REQUIRED] [bit] NOT NULL,

[EDITABLE] [bit] NULL,

[LOWRANGE] [nvarchar](50) NULL,

[HIGHRANGE] [nvarchar](50) NULL,

[USEKEY] [bit] NULL,

[SOURCE TABLE] [nvarchar](50) NULL,

[SOURCE FIELD] [nvarchar](50) NULL,

CONSTRAINT [PK_Structure_1] PRIMARY KEY CLUSTERED

(

[ID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]


Template1

Type topic text here.