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

 

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

 

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

       

        아이디 :

        <asp:TextBox ID="UserID" runat="server"></asp:TextBox><br />

        암호 :

        <asp:TextBox ID="Password" runat="server"></asp:TextBox><br />

        이름 :

        <asp:TextBox ID="Name" runat="server"></asp:TextBox><br />

        나이 :

        <asp:TextBox ID="Age" runat="server"></asp:TextBox><br />

        <br />

        <asp:Button ID="btnSubmit" runat="server" Text="전송" onclick="btnSubmit_Click" /><br />

       

    </div>

    </form>

</body>

</html>

 




 

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

 


==> [FrmRequest.aspx.cs] 소스

 


using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

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

{

    protected void Page_Load(object sender, EventArgs e)

    {

        string strUserId = "";

        string strPassword = String.Empty;

        string strName = "";

        string strAge = String.Empty;

 

        //[1] Request 객체의 QueryString 컬렉션

        strUserId =

            Request.QueryString["UserID"];

 

        //[2] Request 객체의 Params 컬렉션

        strPassword =

            Request.Params["Password"];

 

        //[3] Request 객체의 Form 컬렉션

        strName = Request.Form["Name"];

 

        //[4] Request 객체 자체로 받기

        strAge = Request["Age"];

        string strMsg = String.Format(

            "입력하신 아이디는 {0}이고<br />"

            + "암호는 {1}입니다.<br />"

            + "이름은 {2}이고,<br />"

            + "나이는 {3}살 입니다.<br />",

            strUserId, strPassword,

            strName, strAge);

        Response.Write(strMsg);

    }

 

    protected void btnSubmit_Click(object sender, EventArgs e)

    {

        // Empty

        // ASP.NET에서는 Request개체 보다는

        // 컨트롤의 속성을 사용해서 값을 받는다.

        string name = Name.Text; //

        int age = Convert.ToInt16(Age.Text); //

    }

}

 

 

 


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

 


[실행결과]

--> 아래그림에서 각 '텍스트 박스'에 입력한 데이터 중 "아이디"는 입력이 되지 않았다. 이것은 [FrmRequest.aspx.cs]코드의 strUserId = Request.QueryString["UserID"];부분에서 Request 객체의 QueryString 컬렉션으로 설정하였기 때문이다.(즉, "UserID"는 "QueryString"으로만 출력시킬 수 있다.)





--> 이번에는 '인터넷주소창'에 http://localhost:1148/WebASPNET/FrmRequest.aspx뒤에
 ?userID=a&Password=77&Name=aaa&Age=25QueryString입력하였는데 "이름"부분에는 입력한 QueryString이 출력되지 않은 것을 볼 수 있다. 이는 [FrmRequest.aspx.cs]코드의
strName = Request.Form["Name"];부분에서 Request 객체의 Form 컬렉션으로 설정하였기 때문이다.(즉, "Name"은 "폼(Form)"으로만 출력시킬 수 있다.)






Posted by holland14
: