This project is read-only.

ASP.NET WebForms Integration

Overview

While SpecExpress is stable, the ASP.NET WebForms integration should be considered Beta!

This will add client-side Required Field Validators, while all additional validation is performed server side.

1. Setup Page

Add a reference to SpecExpress.Web.

Add Server Controls to Page

<%@ Import Namespace="SpecExpress" %>
<%@ Register Namespace="SpecExpress.Web" Assembly="SpecExpress.Web" TagPrefix="spec" %>

Add a Specification Manager to the page.

 <spec:SpecificationManager ID="SpcManager" runat="server"
            OnValidationNotification="Validate_Invalid"
            OnGetObject="GetProvider"
            TypeToValidate="SpecExpress.Quickstart.Domain.Entities.Provider, SpecExpress.Quickstart.Domain" />

TypeToValidate - Fully qualified class name of entity that is being validated
OnGetObject Optional - Method in code behind that returns a fully populated object from the ASPX page.
OnValidationNotification Optional - Event to fire in code-behind if Validation Errors are found .

2. Add Property Validators

 <div>
	<asp:Label ID="lblFirstName" runat="server" AssociatedControlID="txtFirstName" Text="First Name"/>
	<asp:TextBox ID="txtFirstName" runat="server" />    
	<spec:Validator ID="vldFirstName" runat="server" PropertyName="FirstName" ControlToValidate="txtFirstName"   />             
</div>              
  • If a label is defined, the value of the label will be used to override the Property Name.

Additional Functionality

If a Specification returns an Validation Error for a property that doesn't have a corresponding Validator, that error will be displayed in the Validation Summary, if one is on your page.

Last edited Jun 16, 2011 at 4:18 AM by rbell80134, version 6

Comments

ikola Jan 18, 2015 at 1:42 PM 
Hi, thanks for SpecExpress.
But there is a problem in Asp.net Webform integration of SpecExpress. Error description is below.
In addition, There is no package for SpecExpress.Web in Nuget Package Manager.


Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
SpecExpress.Web.SpecificationManager.BuildObjectToValidateFromControls() in c:\Users\rbell.BELLSGATE\Documents\Visual Studio 2010\Projects\SpecExpress\SpecExpress\src\SpecExpress.Web\SpecificationManager.cs:190
SpecExpress.Web.SpecificationManager.OnServerValidate(String value) in c:\Users\rbell.BELLSGATE\Documents\Visual Studio 2010\Projects\SpecExpress\SpecExpress\src\SpecExpress.Web\SpecificationManager.cs:92
System.Web.UI.WebControls.CustomValidator.EvaluateIsValid() +92
System.Web.UI.WebControls.BaseValidator.Validate() +92
System.Web.UI.Page.Validate() +165
System.Web.UI.Page.Validate(String validationGroup) +9717115
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +75
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9715218
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1719

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.5.22.0