' ASPX_Validation_Controls_Response_Redirect.vb.txt ' Writen by Dan Garlen dan.g@kgsystems.com 2/22/04 ' ' Add two blank WebForms to project ' "ValidationControls.aspx" & ' "ShowValid.aspx" ' ' Set ValidationControls.aspx as Startup Form ' Replace/Paste as follows into "ValidationControls.aspx" Public Class ValidationControls Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Protected WithEvents rfvName As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents txtName As System.Web.UI.WebControls.TextBox Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button Protected WithEvents ValidationSummary1 As System.Web.UI.WebControls.ValidationSummary Protected WithEvents txtAge As System.Web.UI.WebControls.TextBox Protected WithEvents rvAge As System.Web.UI.WebControls.RangeValidator Protected WithEvents txtPassword1 As System.Web.UI.WebControls.TextBox Protected WithEvents txtPassword2 As System.Web.UI.WebControls.TextBox Protected WithEvents rfvPassword1 As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents rfvPassword2 As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents cvPassword As System.Web.UI.WebControls.CompareValidator Protected WithEvents txtDOB As System.Web.UI.WebControls.TextBox Protected WithEvents cvDOB As System.Web.UI.WebControls.CompareValidator Protected WithEvents rfvDOB As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents lblResults As System.Web.UI.WebControls.Label 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then With rfvName .ErrorMessage = "Name Required" .Text = "*" ' Set Text property when using ValidationSummary Control .ControlToValidate = "txtName" End With With rvAge .ErrorMessage = "Age out of range" .Text = "*" .ControlToValidate = "txtAge" .MinimumValue = 0 .MaximumValue = 140 .Type = ValidationDataType.Integer End With With rfvPassword1 .ErrorMessage = "Password Required" .Text = "*" .ControlToValidate = "txtPassword1" End With With rfvPassword2 .ErrorMessage = "Password Required" .Text = "*" .ControlToValidate = "txtPassword1" End With With cvPassword .ErrorMessage = "Passwords not the same" .Text = "*" .ControlToCompare = "txtPassword1" .ControlToValidate = "txtPassword2" .Type = ValidationDataType.String End With With cvDOB .ErrorMessage = "Invalid Date of Birth" .Text = "*" .ControlToValidate = "txtDOB" .Type = ValidationDataType.Date .Operator = ValidationCompareOperator.DataTypeCheck End With With rfvDOB .ErrorMessage = "Date of Birth Required" .Text = "*" .ControlToValidate = "txtDOB" End With Else End If 'Put user code to initialize the page here End Sub Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click If Page.IsValid Then Dim url As String = "ShowValid.ASPX?Name=" + txtName.Text + "&DOB=" + txtDOB.Text Response.Redirect(url) End If End Sub End Class ' ====================================================================================================== ' Switch to HTML view and replace the body section with the following

Name:

Age(optional):

Password:  Confirm:

DOB:

' ====================================================================================================== ' Replace/Paste as follows into "ShowValid.aspx": Public Class ShowValid_ASPX Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Protected WithEvents lblWelcome As System.Web.UI.WebControls.Label 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim bolOK As Boolean = True Dim strName As String = Request.QueryString("Name") Dim strDOB As String = Request.QueryString("DOB") If strName Is Nothing Then bolOK = False If strDOB Is Nothing Then bolOK = False If (bolOK) Then lblWelcome.Text = "Welcome: " + strName + "
Born: " + strDOB Else lblWelcome.Text = "Invalid Access" End If End Sub End Class ' ====================================================================================================== ' Change to HTML view and replace the body section with the following:

Return to ValidationControls