본문 바로가기

   
Programming/ASP.NET(4.0)

ASP.NET PlaceHolder, Validator, RequireFieldValidator, CompareVaildator, RangeValidator, CustomValidator

반응형

ASP.NET PlaceHolder, Validator, RequireFieldValidator, CompareVaildator, RangeValidator, CustomValidator


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

 

<!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>

   

       <h2>

                    Ex21_PlaceHolder.aspx</h2>

             <br />

             <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

             <br />

             <h3>

                    종로<br />

                    <br />

                    <br />

                    을지로<br />

             </h3>

             <h3>

                    <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

             </h3>

             <h3>

                    <br />

                    동대문<br />

                    <br />

                    <br />

                    이문동<br />

                    <br />

                    <br />

             </h3>

             <br />

             <br />

   

    </div>

    </form>

</body>

</html>

 

 



using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class Ex21_PlaceHolder : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

    }

       protected void Button1_Click(object sender, EventArgs e)

       {

             //플레이스홀더는 렌더링에서 아예빠진다. 자리만 맡아준다.

             //자리만 맡아주고 렌더링은 하지 않는다.

             //플레이스홀더의 자식형태로 집어넣는것.

             Button btn = new Button();

             btn.Text = "버스";

 

             //this.Controls.Add(btn);

             PlaceHolder1.Controls.Add(btn);

       }

}

 






                           







                        



 


                





속성



소스

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

 

<!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>

 

       <script type="text/javascript">

             //이미 Check자바스크립트를 사용하기로 했기 때문에

             //CustomValidator1가 호출하는 함수

             function Check(sender, args) {

 

                    //1. 검사할 값 얻어오기

                    //document.getElementById("TextBox1")

                    var num = args.Value; //TextBox1의 값

 

                    //2. 유효성 검사(내맘대로~)

                    if (num % 7 == 0)

                    //통과 - 3. 결과통보

                           args.IsValid = true;

 

                    else

                    //실패 - 3. 결과통보

                           args.IsValid = false;

             }

       </script>

</head>

<body>

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

    <div>

   

       Ex26_customValidator.aspx<br />

             <br />

             숫자입력(7의 배수만 입력)<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

             <asp:CustomValidator ID="CustomValidator1" runat="server"

                    ClientValidationFunction="Check" ControlToValidate="TextBox1"

                    ErrorMessage="숫자입력(7의 배수만 입력)"></asp:CustomValidator>

             <br />

             <br />

             <asp:Button ID="Button1" runat="server" Text="Button" />

             <br />

             <br />

   

    </div>

    </form>

</body>

</html>

 

 


반응형