QnA
사용언어
(칠해주세요) => (C#,VB) |
사용툴 (VS) : VS2013 |
운영체제 (OS) : 윈도우 8.1 |
상세언어(칠해주세요.)
=> 1) ASP.NET, 2) ASP.NET MVC, 3) ASP.NET AJAX |
jsp 배우다가 asp.net 을 배우게 됬는데요. 일단 기본 소스가
post방식과 get 방식으로 다른 웹폼에 데이터 전달 하는 기본적인 부분에서 잘 안돼네요;;
WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
전달값 : <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="버튼" [안내]태그제한으로등록되지않습니다-xxxxxxxxxxxxOnClick="Button1_Click" />
</div>
</form>
</body>
</html>
.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("~/WebForm2.aspx);
}
}
}
------------------------------------------------------------------------------------
WebForm2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label id="label1" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string aa = Request.Form["TextBox1"];
if(aa != null){
label1.Text = aa;
}
else
{
label1.Text = "값 없음";
}
}
}
}
이런데 텍스트박스에 값을 입력하고 전송해도 계속 값 없음 으로 나오는데 이유를 모르겠어요..
aa변수에도 null로 들어오고요..
그리고 WebForm1 에서 버튼 클릭 이벤트를
Response.Redirect("~/WebForm2.aspx?aa = " + TextBox1.Text); 로 수정 후
WebForm1 텍스트박스에 11 입력 후 버튼 클릭하면
WebForm2 이동 후 주소창에
http://localhost:58876/WebForm2?aa%20=%2011 이렇게 출력되는데 왜 이렇게 나오는지 도통 이유를
모르겠씁니다. ㅠㅠ
첫댓글 우선 오타를 오면... Response.Redirect("~/WebForm2.aspx?aa = " + TextBox1.Text); 공백값이 보이네요. Response.Redirect("~/WebForm2.aspx?aa=" + TextBox1.Text); 이렇게 하셔야 합니다.
그리고 asp.net 을 post 로 전송하는 방법은 javascript 로 해야 합니다. 예제는 ... http://blog.danggun.net/1066