GSI


-- Join.aspx--
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Join.aspx.cs" Inherits="AjaxTest.Join" %>

<!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>
    <style type="text/css">
        body{ font-size:10pt; font-family:돋움;}
        .panel{position:fixed; float:right;}
    </style>
    <script type="text/javascript" language="javascript">
        var xmlHttp;
       
        function createXMLHttpRequest()
        {
            if (window.ActiveXObject)
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
            }
            else if (window.XMLHttpRequest)
            {
                xmlHttp = new XMLHttpRequest();
            }
        }
       
        function idCheck()
        {
            var id = document.getElementById("txtId").value;
            var hid = document.getElementById("HiddenField1");
            createXMLHttpRequest();
            xmlHttp.open("get", "id_check.aspx?id=" + id, false);
            xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xmlHttp.send(null);
            if (xmlHttp.readyState == 4) //받을 문자가 있을떄
            {
                if (xmlHttp.status == 200) //정상적으로 받았을때
                {
                    var returnvalue = xmlHttp.responseText;  // 받는 문
                    if(returnvalue == "0")
                    {
                        alert('사용가능합니다.');
                        hid.value = 1;   //1번 퀴즈의 닶                        
                    }
                    else
                    {
                        alert('존재하는 아이디 입니다.');
                        id = "";
                    }
                }
                else
                {
                    alert('error..');
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>이름</td>
                    <td>
                        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>주민등록번호</td>
                    <td>
                        <asp:TextBox ID="txtRegNo1" runat="server"></asp:TextBox>-<asp:TextBox ID="txtRegNo2" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>ID</td>
                    <td>
                        <asp:TextBox ID="txtId" runat="server"></asp:TextBox>
                        <input type="button" value="중복확인" onclick="idCheck()" />
                    </td>
                </tr>
                <tr>
                    <td>비밀번호</td>
                    <td>
                        <asp:TextBox ID="txtPwd1" runat="server" TextMode="Password"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>비밀번호확인</td>
                    <td>
                        <asp:TextBox ID="txtPwd2" runat="server" TextMode="Password"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>주소</td>
                    <td>
                        <asp:TextBox ID="txtAddr1" runat="server" Width="237px"></asp:TextBox>
                        <asp:Button ID="btnAddr" runat="server" Text="주소찾기" />
                    </td>
                </tr>
                <tr>
                    <td>상세주소</td>
                    <td>
                        <asp:TextBox ID="txtAddr2" runat="server" Width="316px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>우편번호</td>
                    <td>
                        <asp:TextBox ID="txtZip1" runat="server" Width="49px"></asp:TextBox>
                        -
                        <asp:TextBox ID="txtZip2" runat="server" Width="49px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>전화번호</td>
                    <td>
                        <asp:TextBox ID="txtPhone1" runat="server" Width="49px"></asp:TextBox>
                        -&nbsp;
                        <asp:TextBox ID="txtPhone2" runat="server" Width="49px"></asp:TextBox>
                        -
                        <asp:TextBox ID="txtPhone3" runat="server" Width="49px"></asp:TextBox>&nbsp;
                    </td>
                </tr>
                <tr>
                    <td>핸드폰</td>
                    <td>
                        <asp:TextBox ID="txtCell1" runat="server" Width="49px"></asp:TextBox>
                        -
                        <asp:TextBox ID="txtCell2" runat="server" Width="49px"></asp:TextBox>
                        -
                        <asp:TextBox ID="txtCell3" runat="server" Width="49px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>이메일</td>
                    <td>
                        <asp:TextBox ID="txtEmail" runat="server" Width="249px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>메일 수신여부</td>
                    <td>수신하시겠습니까?<asp:CheckBoxList ID="CKYN" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" >
                        <asp:ListItem Text="YES" Value="1"></asp:ListItem>
                        <asp:ListItem Text="NO" Value="0"></asp:ListItem>
                        </asp:CheckBoxList>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <asp:Button ID="btnJoin" runat="server" Text="가입하기" OnClick="btnJoin_Click" />
                    </td>
                </tr>
            </table>
        </div>
        <div id="eee" style="display:none;">
            <p style="color:Red; font-weight:bold;" id="sssss">중복아이디 확인을 해주세요.</p>
        </div>
        <asp:HiddenField ID="HiddenField1" runat="server" Value="0" />
    </form>
</body>
</html>

-- Join.aspx.cs--
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

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

        }

        protected void btnJoin_Click(object sender, EventArgs e)
        {
            if (Request.Form["HiddenField1"].ToString() == "1")
            {
                string strSql = "exec UserJoin ";
                strSql += "'" + txtId.Text + "','" + txtPwd1.Text + "','" + txtName.Text + "'," + txtRegNo1.Text;
                strSql += "," + txtRegNo2.Text + ",'" + txtAddr1.Text + "','" + txtAddr2.Text + "'," + txtZip1.Text;
                strSql += "," + txtZip2.Text + "," + txtPhone1.Text + "," + txtPhone2.Text + "," + txtPhone3.Text;
                strSql += "," + txtCell1.Text + "," + txtCell2.Text + "," + txtCell3.Text + ",'" + txtEmail.Text + "'," + CKYN.SelectedValue.ToString();

                SqlConnection objCon = new SqlConnection(Connected());
                SqlCommand objCmd = new SqlCommand(strSql, objCon);
                objCon.Open();
                objCmd.ExecuteNonQuery();
                objCon.Close();
            }
            else
            {
                String csname1 = "IDCHECK";
                Type cstype = this.GetType();
                ClientScriptManager cs = Page.ClientScript;

                if (!cs.IsStartupScriptRegistered(cstype, csname1))
                {
                    String cstext1 = "document.getElementById('eee').style.display = '';";
                    cs.RegisterStartupScript(cstype, csname1, cstext1, true);
                }
            }
        }

        public string Connected()
        {
            ConnectionStringSettings settings;
            settings = System.Configuration.ConfigurationManager.ConnectionStrings["tomochanwebConnectionString"];
            string connectionString = settings.ConnectionString;
            return connectionString;
        }
    }
}

-- id_check.aspx--
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="id_check.aspx.cs" Inherits="AjaxTest.id_check" %>

<!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>
   
    </div>
    </form>
</body>
</html>

-- id_hceck.aspx.cs--
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace AjaxTest
{
    public partial class id_check : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //리턴할 값을 넣을 변수 선언
            string strRturn = "0";
            //쿼리스트링 값 받는 변수 선언 및 할당
            string strID = Request.QueryString["id"].ToString();
            // 아이디 체크를 위한 쿼리
            string strSql = "SELECT Count(*) FROM user_info where uid = '" + strID + "'";
            //콘넥션 개체 생성
            SqlConnection objCon = new SqlConnection(Connected());
            SqlCommand objCmd = new SqlCommand(strSql, objCon);
            objCon.Open();
            SqlDataReader reader = objCmd.ExecuteReader();
            while (reader.Read())
            {
                //데이터 리드를 통한 쿼리값을 받음
                strRturn = reader[0].ToString();
            }
            reader.Close();
            objCon.Close();

            // utf-8로 인코딩하여 join.aspx페이지에 strRturn값을 보내줌.
            Response.ContentType = "UTF-8";
            Response.Write(strRturn);
            Response.Flush();
            Response.End();
        }
       
        public string Connected()
        {
            ConnectionStringSettings settings;
            settings = System.Configuration.ConfigurationManager.ConnectionStrings["tomochanwebConnectionString"];
            string connectionString = settings.ConnectionString;
            return connectionString;
        }
    }
}

Posted by gsi
: