Freigeben über


Testseite für Gültigkeitsprüfungsbeispiele

Im Folgenden finden Sie eine Testseite und ihre CodeBehind-Datei für die Beispiele für Bestätigungssteuerelemente. Eine Anleitung zum Kompilieren und Erstellen dieses Beispiels finden Sie unter Beispiele für Bestätigungssteuerelemente.

Testseite

<%-- ValTest.aspx --%>
<%@ Page language="c#" Src="ValTest.aspx.cs" AutoEventWireup="false" Inherits="DomValidatorTest.ValTest" %>
<%@ Register TagPrefix="domval" Namespace=DomValidators Assembly=DomValidators %>

<HTML>
  <HEAD>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<meta content="Microsoft Visual Studio .NET" name=GENERATOR>
<meta content=C# name=CODE_LANGUAGE>
<meta content="JavaScript (ECMAScript)" name=vs_defaultClientScript>
<meta content="Internet Explorer 3.02 / Navigator 3.0" name=vs_targetSchema>
<title>DOM Validators Test</title>
  </HEAD>
<body>
<form id=ValTest method=post runat="server">
<P><FONT face=Verdana size=5>DOM Validators Test</FONT></P>
<P>
<TABLE cellSpacing=1 cellPadding=1 width=602 border=0 height=131>
  <TR>
    <TD style="WIDTH: 82px">Name:</TD>
    <TD style="WIDTH: 164px"><asp:textbox id=txtName runat="server"></asp:textbox></TD>
    <TD><domval:RequiredDomValidator id=valRequired runat="server" ErrorMessage="Required." ControlToValidate="txtName"></domval:RequiredDomValidator></TD>
    </TR>
  <TR>
    <TD style="WIDTH: 82px">Postal&nbsp;Code:</TD>
    <TD style="WIDTH: 164px"><asp:textbox id=txtPostcode runat="server"></asp:textbox></TD>
    
    <TD><domval:RegexDomValidator id=valRegex runat="server" ErrorMessage="Postcode must be 9999." ControlToValidate="txtPostcode" ValidationExpression="\d{4}"></domval:RegexDomValidator></TD>
    </TR>
    </TABLE></P>
<P>
<asp:Button id=cmdSubmit runat="server" Text="Submit" ></asp:Button>&nbsp;&nbsp; 
<asp:Button id=cmdCancel runat="server" Text="Cancel" CausesValidation="False"></asp:Button>
</P>
<asp:panel id=Panel1 runat="server" 
BorderColor="#00C000" BorderStyle="Solid" BorderWidth="2px" Height="55px" 
Width="197px">
<P>
Browser: <asp:Label id=lblBrowserName Runat="server">  </asp:Label><br>
Version: <asp:Label id=lblBrowserVersion Runat="server">  </asp:Label><br>
Script Version: <asp:Label id=lblScriptVersion Runat="server">  </asp:Label><br>
DOM Version: <asp:Label id=lblDomVersion Runat="server">  </asp:Label><br>
Submit clicks: <asp:Label id=lblSubmitCount Runat="server"> 0 </asp:Label><br>
Cancel clicks: <asp:Label id=lblCancelCount Runat="server"> 0 </asp:Label><br>
</P></asp:panel>
</form>
   
  </body>
</HTML>
[Visual Basic]
<%-- ValTest.aspx --%>
<%@ Page language="VB" Src="ValTest.aspx.vb" AutoEventWireup="false" Inherits="DomValidatorTest.ValTest" debug=true%>
<%@ Register TagPrefix="domval" Namespace=DomValidators Assembly=DomValidators %>

<HTML>
  <HEAD>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<meta content="Microsoft Visual Studio .NET" name=GENERATOR>
<meta content=C# name=CODE_LANGUAGE>
<meta content="JavaScript (ECMAScript)" name=vs_defaultClientScript>
<meta content="Internet Explorer 3.02 / Navigator 3.0" name=vs_targetSchema>
<title>DOM Validators Test</title>
  </HEAD>
<body>
<form id=ValTest method=post runat="server">
<P><FONT face=Verdana size=5>DOM Validators Test</FONT></P>
<P>
<TABLE cellSpacing=1 cellPadding=1 width=602 border=0 height=131>
  <TR>
    <TD style="WIDTH: 82px">Name:</TD>
    <TD style="WIDTH: 164px"><asp:textbox id=txtName runat="server"></asp:textbox></TD>
    <TD><domval:RequiredDomValidator id=valRequired runat="server" ErrorMessage="Required." ControlToValidate="txtName"></domval:RequiredDomValidator></TD>
    </TR>
  <TR>
    <TD style="WIDTH: 82px">Postal&nbsp;Code:</TD>
    <TD style="WIDTH: 164px"><asp:textbox id=txtPostcode runat="server"></asp:textbox></TD>
    
    <TD><domval:RegexDomValidator id=valRegex runat="server" ErrorMessage="Postcode must be 9999." ControlToValidate="txtPostcode" ValidationExpression="\d{4}"></domval:RegexDomValidator></TD>
    </TR>
    </TABLE></P>
<P>
<asp:Button id=cmdSubmit runat="server" Text="Submit" ></asp:Button>&nbsp;&nbsp; 
<asp:Button id=cmdCancel runat="server" Text="Cancel" CausesValidation="False"></asp:Button>
</P>
<asp:panel id=Panel1 runat="server" 
BorderColor="#00C000" BorderStyle="Solid" BorderWidth="2px" Height="55px" 
Width="197px">
<P>
Browser: <asp:Label id=lblBrowserName Runat="server">  </asp:Label><br>
Version: <asp:Label id=lblBrowserVersion Runat="server">  </asp:Label><br>
Script Version: <asp:Label id=lblScriptVersion Runat="server">  </asp:Label><br>
DOM Version: <asp:Label id=lblDomVersion Runat="server">  </asp:Label><br>
Submit clicks: <asp:Label id=lblSubmitCount Runat="server"> 0 </asp:Label><br>
Cancel clicks: <asp:Label id=lblCancelCount Runat="server"> 0 </asp:Label><br>
</P></asp:panel>
</form>
   
  </body>
</HTML>

CodeBehind-Datei für die Testseite

// ValTest.aspx.cs.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace DomValidatorTest
{
    /// <summary>
    /// Summary description for ValTest.
    /// </summary>
    public class ValTest : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Label lblSubmitCount;
        protected System.Web.UI.WebControls.Label lblCancelCount;
        protected System.Web.UI.WebControls.Label lblBrowserName;
        protected System.Web.UI.WebControls.Label lblBrowserVersion;
        protected System.Web.UI.WebControls.Label lblScriptVersion;
        protected System.Web.UI.WebControls.Label lblDomVersion;
        protected System.Web.UI.WebControls.TextBox txtName;
        protected System.Web.UI.WebControls.TextBox txtPostcode;
        protected System.Web.UI.WebControls.Button cmdSubmit;
        protected System.Web.UI.WebControls.Button cmdCancel;
        protected DomValidators.RequiredDomValidator valRequired;
   protected DomValidators.RegexDomValidator valRegex;
        protected System.Web.UI.WebControls.Panel Panel1;
    
        public ValTest() {
            Page.Init += new System.EventHandler(Page_Init);
        }

        private void Page_Load(object sender, System.EventArgs e)
        {
            
            lblBrowserName.Text = Request.Browser.Browser;
            lblBrowserVersion.Text = Request.Browser.Version.ToString();
            lblScriptVersion.Text = Request.Browser.EcmaScriptVersion.ToString();
            lblDomVersion.Text = Request.Browser.W3CDomVersion.ToString();

        }

        private void Page_Init(object sender, EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Windows Form designer.
            //
            InitializeComponent();
        }

#region Web Form Designer generated code
        /// <summary>
        /// Required method for designer support; do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {    
            this.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click);
            this.cmdCancel.Click += new System.EventHandler(this.cmdCancel_Click);
            this.Load += new System.EventHandler(this.Page_Load);
        }
#endregion

        private void SubmitClicked() {
            int okClicked = int.Parse(lblSubmitCount.Text) + 1;
            lblSubmitCount.Text = okClicked.ToString();
        }

        private void CancelClicked() {
            int cancelClicked = int.Parse(lblCancelCount.Text) + 1;
            lblCancelCount.Text = cancelClicked.ToString();
        }

        private void cmdSubmit_Click(object sender, EventArgs e){
            SubmitClicked();
        }

        private void cmdCancel_Click(object sender, EventArgs e) {
            CancelClicked();
        }
    }
}
[Visual Basic]
' ValTest.aspx.vb.
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls


Namespace DomValidatorTest
   ' <summary>
   ' Summary description for ValTest.
   ' </summary>
   Public Class ValTest
      Inherits System.Web.UI.Page
      Protected lblSubmitCount As System.Web.UI.WebControls.Label
      Protected lblCancelCount As System.Web.UI.WebControls.Label
      Protected lblBrowserName As System.Web.UI.WebControls.Label
      Protected lblBrowserVersion As System.Web.UI.WebControls.Label
      Protected lblScriptVersion As System.Web.UI.WebControls.Label
      Protected lblDomVersion As System.Web.UI.WebControls.Label
      Protected txtName As System.Web.UI.WebControls.TextBox
      Protected txtPostcode As System.Web.UI.WebControls.TextBox
      Protected WithEvents cmdSubmit As System.Web.UI.WebControls.Button
      Protected WithEvents cmdCancel As System.Web.UI.WebControls.Button
      Protected valRequired As DomValidators.RequiredDomValidator
      Protected valRegex As DomValidators.RegexDomValidator
      Protected Panel1 As System.Web.UI.WebControls.Panel
      
      Public Sub New()
         AddHandler Page.Init, AddressOf Page_Init
      End Sub
      
      Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
         lblBrowserName.Text = Request.Browser.Browser
         lblBrowserVersion.Text = Request.Browser.Version.ToString()
         lblScriptVersion.Text = Request.Browser.EcmaScriptVersion.ToString()
         lblDomVersion.Text = Request.Browser.W3CDomVersion.ToString()
      End Sub
      
      Private Sub Page_Init(sender As Object, e As EventArgs)
         '
         ' CODEGEN: This call is required by the ASP.NET Windows Form designer.
         '
         InitializeComponent()
      End Sub

#Region "Web Form Designer generated code"
      ' <summary>
      ' Required method for designer support; do not modify
      ' the contents of this method with the code editor.
      ' </summary>
      Private Sub InitializeComponent()
      End Sub
#End Region

      Private Sub SubmitClicked()
         Dim okClicked As Integer = Integer.Parse(lblSubmitCount.Text) + 1
         lblSubmitCount.Text = okClicked.ToString()
      End Sub
      
      Private Sub CancelClicked()
         Dim cancelClicked As Integer = Integer.Parse(lblCancelCount.Text) + 1
         lblCancelCount.Text = cancelClicked.ToString()
      End Sub
      
      Private Sub cmdSubmit_Click(sender As Object, e As EventArgs) Handles cmdSubmit.Click
         SubmitClicked()
      End Sub
      
      Private Sub cmdCancel_Click(sender As Object, e As EventArgs) Handles cmdCancel.Click
         CancelClicked()
      End Sub 
   End Class 
End Namespace

Siehe auch

Beispiele für Bestätigungssteuerelemente | Beispiel für ein grundlegendes Bestätigungssteuerelement | Beispiel für ein Bestätigungssteuerelement für erforderliche Felder | Beispiel für ein Bestätigungssteuerelement für reguläre Ausdrücke | Skriptbibliothek für Gültigkeitsprüfungsbeispiele | Konfigurationsdatei für Bestätigungsbeispiele | Entwickeln eines Bestätigungssteuerelements