ASP.NETコントロールのRequiredFieldValidatorコントロール

4121 ワード

役割:textboxまたは他の入力ボックスを非空検証する.
属性:ControlToValidate(目的のコントロールを選択)
ErrorMessage(エラー、表示するエラー情報を入力)
適用方法:
プロトタイプ:
 
Demo
フロントエンド:
<span style="font-family:KaiTi_GB2312;font-size:18px;"><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="    .aspx.cs" Inherits="    1.    " %>

<!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></title>
    <style type="text/css">
        .auto-style1 {
            position: absolute;
            top: 159px;
            left: 360px;
            z-index: 1;
        }
        .auto-style2 {
            position: absolute;
            top: 190px;
            left: 360px;
            z-index: 1;
            bottom: 452px;
            width: 81px;
        }
        .auto-style3 {
            position: absolute;
            top: 158px;
            left: 436px;
            z-index: 1;
        }
        .auto-style4 {
            position: absolute;
            top: 189px;
            left: 435px;
            z-index: 1;
        }
        .auto-style5 {
            position: absolute;
            top: 159px;
            left: 601px;
            z-index: 1;
        }
        .auto-style6 {
            position: absolute;
            top: 196px;
            left: 605px;
            z-index: 1;
            height: 15px;
            width: 109px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
        <asp:Label ID="Label1" runat="server" CssClass="auto-style1" Text="   :"></asp:Label>
        <asp:Label ID="Label2" runat="server" CssClass="auto-style2" Text="    :"></asp:Label>
        <asp:TextBox ID="txtUserName" runat="server" CssClass="auto-style3"></asp:TextBox>
        <asp:TextBox ID="txtPwd" runat="server" CssClass="auto-style4"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtUserName" CssClass="auto-style5" ErrorMessage="*      " ForeColor="Red"></asp:RequiredFieldValidator>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtPwd" CssClass="auto-style6" ErrorMessage="*     " ForeColor="Red"></asp:RequiredFieldValidator>
        <p>
             </p>
        <p>
             </p>
        <asp:Button ID="btnLogin" runat="server" style="z-index: 1; left: 389px; top: 259px; position: absolute; width: 63px; bottom: 360px" Text="  " />
        <asp:Button ID="btnSet" runat="server" OnClick="btnSet_Click" style="z-index: 1; left: 559px; top: 262px; position: absolute; width: 64px; height: 21px" Text="  " />
    </form>
</body>
</html>
</span>

バックグラウンド:
<span style="font-family:KaiTi_GB2312;font-size:18px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace     1
{
    public partial class      : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //  
        protected void btnSet_Click(object sender, EventArgs e)
        {
            txtPwd.Text = "";
            txtUserName .Text ="";
        }
        //  
        protected void btnLogin_Click(object sender, EventArgs e)
        {

        }
    }
}</span>

小結
1、いろいろまとめてみましょう.
貴重な時間をありがとう・・・