2012-06-05 5 views
0

가능한 중복 :
asp.net pass a value into next page얻기 텍스트 상자 값

내가 텍스트 상자를 사용하여 사용자의 수량을 요청하고 그것으로 계산을 수행 한 후, 나는에 결과를 표시 할 다른 페이지의 레이블. 여기

는 confirm.aspx.cs

public partial class confirm : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     if (Request.Cookies["user"] != null) 
     { 
      Label2.Text = Server.HtmlEncode(Request.Cookies["user"]["userName"]); 
      Label3.Text = Server.HtmlEncode(Request.Cookies["user"]["email"]); 
      Label1.Text = Server.HtmlEncode(Request.Cookies["user"]["items"]); 

     } 
    } 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
     Session.Add("TextBox1Value", TextBox1.Text); 
     Response.Redirect("total.aspx"); 

    } 
} 

을위한 코드이며, 여기에 내가 잘못이나 될 수있다 생각합니다 어느 곳

public partial class total : System.Web.UI.Page 
{ 
    int totalprice; 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     //Label1.Text = Server.HtmlEncode(Request.Cookies["confirm"]["quantity"]); 
     int quantity = Session["TextBox1Value"]; 

     if (Request.Cookies["user"]["items"] == "Tyres") 
     { 
      totalprice = 20 * quantity; 

      Label2.Text = totalprice.ToString(); 
     } 
    } 
} 

total.aspx.cs, 다른 페이지에 대한 코드입니다 어떻게 할 수 있습니까?

+0

'.Text' 속성은 이미 인코딩됩니다. 이중 인코딩해서는 안됩니다. – SLaks

답변

0

계산을 수행하려면 integer 유형으로 캐스팅해야합니다.

if(Session["TextBox1Value"]!=null) 
{ 
    string strQuantity = Session["TextBox1Value"].ToString(); 
    int quantity=Convert.ToInt32(strQuantity); 
    //now you can use quantity to do all your calculations 
} 
+0

문자열에 오류가 발생했습니다. strQuantity = 세션 [ "TextBox1Value"]; – unknownsatan

+0

오류를 게시 했어야합니다. 세션 [ "TextBox1Value"]을 시도하십시오. ToString() – codingbiz

+0

@AnkurKaushal : Woh! '.ToString()'호출을 놓쳤습니다. 업데이트 된 답변을 확인하십시오. – Shyju

0

가 한 페이지에서 다른 페이지로 값을 전달하는 여러 가지 방법이 있습니다 .. 동일한 주제에 대한 내 대답의

하나는 세부 사항을 얻을 도움이 될 것입니다.

pass a value into next page