当前位置:   article > 正文

使用 asp的标准控件 与 验证控件 以及使用 C#Script 来完成 表单 的输入验证问题_3. 请使用asp的标准控件与撰写c#script(不能使用html tag与javascript)

3. 请使用asp的标准控件与撰写c#script(不能使用html tag与javascript),将网

使用 asp的标准控件 与 验证控件 以及使用 C#Script 来完成 表单 的输入验证问题


一,题目

  1. 请制作一个aspx页面,限定只能使用asp的标准控件与验证控件以及使用C#Script来完成Registration Form的输入验证问题(注意: 不能使用html tag与javascript)。若有错误,需以提醒使用者修改输入讯息,其规则如下图红字的部份(关于Country部份,请列举五个国家即可)。

二, 涉及的知识

1. asp标准控件

2.asp验证控件

学习资源来源 csdn博主文章:Asp.Net的六种验证控件
在这里插入图片描述

3.C#Script

4.正则表达式

学习资源 来源csdn博主文章:

  1. ValidationExpression 验证规则
  2. asp正则表达式大全
  3. 验证方法 ValidationExpression 正则表达式

三,第一种解法:使用验证控件

1.运行截图

加载页面如下
在这里插入图片描述

2.代码实现

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="homework4.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>1-Registration Form的输入验证问题</title>

    <style >
         .label_style {
     
           
            width: 100px;
            margin-bottom: 15px;
            margin-right:15px;
            text-align:right;
            display: inline-block;
        }
          .div_content {
     
            border: solid #000000; /*设置边框样式跟颜色*/
            border-width: 1px; /*设置边框宽度*/
            width: 630px; /*设置div宽度*/
            height: 650px; /*设置div高度*/
            margin: 0 auto; /*设置div居中*/
        }

    </style>
</head>


<body>
    <form id="form1" runat="server">
        <div class="div_content">
            <h2 style="font-weight:bold;margin:30px;">Registration Form</h2>

                <asp:Label  runat="server" class="label_style" >User id:</asp:Label>
                <asp:TextBox ID="user_id" runat="server" Width="150px" ></asp:TextBox>  
                    <asp:RequiredFieldValidator  runat="server"
            	           ControlToValidate="user_id"
                            ErrorMessage="Required "
                            ForeColor ="Red">
                     </asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator 
                        ControlToValidate="user_id"
                        ID="RegularExpressionValidator1"
                        ValidationExpression="\S{5,12}" 
                        runat="server" 
                        ErrorMessage="must be of length 5 to 12"
                         ForeColor ="Red">
                    </asp:RegularExpressionValidator>
            <br />

                <asp:Label  runat="server"  class="label_style" >Password:</asp:Label>
                <asp:TextBox ID="password_id" type="password" runat="server" Width="150px"></asp:TextBox>
                    <asp:RequiredFieldValidator  runat="server"
            	         ControlToValidate="password_id"
                         ErrorMessage="Required "
                         ForeColor ="Red">
                     </asp:RequiredFieldValidator>
                     <asp:RegularExpressionValidator 
                        ControlToValidate="password_id"
                        ValidationExpression="\S{7,12}" 
                        runat="server" 
                        ErrorMessage="must be of length 7 to 12"
                        ForeColor ="Red">
                    </asp:RegularExpressionValidator>
            <br />

                <asp:Label  runat="server"  class="label_style" >Name:</asp:Label>
                <asp:TextBox ID="name_id" runat="server" Width="350px"></asp:TextBox>
                    <asp:RequiredFieldValidator  runat="server"
            	         ControlToValidate="name_id"
                         ErrorMessage="Required "
                         ForeColor ="Red">
                     </asp:RequiredFieldValidator>
                     <asp:RegularExpressionValidator 
                        ControlToValidate="name_id"
                        ValidationExpression="^[a-zA-Z]+$" 
                        runat="server" 
                        ErrorMessage="alphabates only"
                         ForeColor =
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/701469
推荐阅读
相关标签
  

闽ICP备14008679号