FormParameter::FormField Property
Gets or sets the name of the form variable that the parameter binds to.
Assembly: System.Web (in System.Web.dll)
Property Value
Type: System::StringA string that identifies the form variable to which the parameter binds.
The FormField identifies a name/value pair that is passed in the Form collection. While the FormField property identifies the name of the pair, the FormParameter binds to its corresponding value at run time. If the expected form variable string name/value pair is not passed to the ASP.NET Web page in the collection, the Evaluate method binds the parameter to the value of the DefaultValue property, if it is set. If the DefaultValue is not set, the Evaluate method fails to bind the parameter to a value.
The following code example demonstrates how to display filtered data using an ObjectDataSource control and a FormParameter to retrieve data from a middle-tier business object and a GridView control to display the results.
The code example consists of a TextBox, a GridView control, the ObjectDataSource control, and a submit button. By default, the TextBox is populated with the name of one of the Northwind Traders employees. The GridView displays information about the employee identified by the name in the TextBox. To retrieve data on another employee, enter the full name of the employee in the TextBox and click the button.
The FilterExpression property specifies an expression used to filter the data retrieved by the SelectMethod. This property uses parameter placeholders that are evaluated to the parameters contained in the FilterParameters collection. In this example, the parameter placeholder is a FormParameter bound to the value of the TextBox control.
The following code example shows the middle-tier business object that the previous code example uses. This example consists of two basic classes: The EmployeeLogic class encapsulates business logic, and the NorthwindEmployee class is a model class that contains only the basic functionality required to load and persist data from the data tier. For simplicity, the EmployeeLogic class creates a static set of data, rather than retrieving the data from a data tier. It is also helpful for this example, because the sample relies on the user to provide the full name of a Northwind Traders employee to demonstrate filtering. For a complete working example, you must compile and use these classes with the ASP.NET code examples provided.
Security Note |
|---|
The FormParameter does not validate the value passed by the form element in any way; it uses the raw value. In most cases, you can validate the value of the FormParameter before it is used by a data source control by handling an event, such as the Selecting, Updating, Inserting, or Deleting event exposed by the data source control you are using. If the value of the parameter does not pass your validation tests, you can cancel the data operation by setting the Cancel property of the associated CancelEventArgs class to true. |
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Security Note