* "CompareValidator"컨트롤은 "암호확인"할 때 주로 쓰는 유효성 검사 컨트롤이다. 여기서는 "ASP.NET의 유효성 검사 컨트롤"인 [FrmCompareValidator.aspx] 와 "HTML레벨"의 [FrmCompareValidator.htm]의 예제로 각각 비교해보았다.





==> [FrmCompareValidator.aspx] 소스 및 디자인

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FrmCompareValidator.aspx.cs" Inherits="FrmCompareValidator" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

   

   

   

        비교<br />

        <br />

        암호 :

        <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>

        <asp:CompareValidator ID="valPassword" runat="server"

            ControlToValidate="txtPassword"

            ControlToCompare="txtPasswordConfirm"

            Type="String"

            ErrorMessage="암호를 확인하세요."></asp:CompareValidator>

        <br />

        암호확인 ;

        <asp:TextBox ID="txtPasswordConfirm" runat="server"></asp:TextBox>

        <br />

        <br />

        <asp:LinkButton ID="btnLogin" runat="server">로그인</asp:LinkButton>

   

   

   

    </div>

    </form>

</body>

</html>

 

 


 

 


-------------------------------------------------------------------------------------

 


[실행결과]

--> 아래그림에서 첫번째 텍스트박스에 텍스트('12345')를 입력하고 아래의 텍스트박스에 포커스를 옮기는 순간 아래그림과같이 "CompareValidator"컨트롤에 빨간글씨로 텍스트가 출력된다.





--> 아래그림은 두 개의 텍스트박스에 모두 똑같은 텍스트('12345')를 입력한 후 '로그인'버튼을 눌렀을 때의 화면이다.




--> 아래그림에서 두 개의 텍스트박스에 다른 텍스트를 입력한 후 '로그인'버튼을 누르면 "CompareValidator"컨트롤에 빨간글씨로 텍스트가 출력된다.

 



-------------------------------------------------------------------------------------

 


==> [FrmCompareValidator.htm] 소스 및 디자인

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>

    <script type="text/javascript">

        function Ok() {

            if (document.getElementById("txtPassword").value !=

                document.getElementById("txtPasswordConfirm")) {

                alert("암호를 틀립니다.");

                document.getElementById("txtPassword").select(); // 선택

            }

            else {

                alert("유효성 검사 통과");

            }

        }

    </script>

</head>

<body>

 

비교<br />

 

암호 : <input type="text" id="txtPassword" name="txtPassword" /><br />

암호확인 : <input type="text" id="txtPasswordConfirm" name="txtPasswordConfirm" /><br />

 

<input type="button" value="확인" onclick="Ok();" />

 

</body>

</html>

 

 




 

 

-------------------------------------------------------------------------------------

 


[실행결과]

--> 아래그림에서 두 개의 텍스트박스에 다른 텍스트를 입력한 후 '확인'버튼을 누르면 아래그림과 같이 "메시지박스"가 출력된다.


 

 

 

Posted by holland14
: