본문 바로가기
ASP.NET

값 전달 하기

by BeGeek 2016. 12. 1.

Sample01.aspx -> Sample02.aspx -> Sample03.aspx로 값 전달

Sample01.aspx

<%@ Page Language="C#" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>sample01</title>
</head>
<body>
   <form action="sample02.aspx" method="get">
        <input type="text" name="UserID" />
       <input type="submit" value="Submit" />
  </form>
</body>
</html>
 

Sample02.aspx

<%@ Page Language="C#" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>sample02</title>
</head>
<body>
   <form action="sample03.aspx" method="get">
       <input type="hidden" name="UserID" value="<%=Request.QueryString["UserID"] %>" />
       <input type="submit" value="Submit" />
  </form>
</body>
</html>
 

 

Sample03.aspx

 <%@ Page Language="C#" %>

<script runat="server">
   
protected void Page_Load(object sender, EventArgs e){
    String userID = Request.QueryString["UserID"];
    Response.Write(userID);
}
  
</script>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>sample02</title>
</head>
<body>
   <form action="sample03.aspx" method="get">
      
  </form>
</body>
</html>

위에는 get방식으로 넘기고 받기고, post방식으로 넘기고 받으려면 html form태그의 method는 post로 바꾸고 <form action="sample02.aspx" method="post">

<form action="sample03.aspx" method="post">

받는곳에서는 <%=Request.QueryString["UserID"] %> 대신 <input type="hidden" name="UserID" value="<%=Request.Form["UserID"] %>" /> 처럼 Request.Form["UserID"] 로 받는다.

 

 

댓글