0

Possible Duplicate:
asp.net pass a value into next page

I am requesting quantity from user using text box and after doing calculations with it, I want to display the result on a label on another page.

Here is the code for 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");

    }
}

and here is the code for another page, total.aspx.cs

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();
        }
    }
}

Anywhere I am may be wrong or any suggestions on how can I do it?

Community
  • 1
  • 1
unknownsatan
  • 731
  • 5
  • 16
  • 24

2 Answers2

0

You need to cast it to integer type to do your calculations.

 if(Session["TextBox1Value"]!=null)
 {
   string strQuantity = Session["TextBox1Value"].ToString();
   int quantity=Convert.ToInt32(strQuantity);
   //now you can use quantity to do all your calculations
 }
Shyju
  • 214,206
  • 104
  • 411
  • 497
0

There are different ways to pass the values from one page to another..

One of my answer on the same topic will help you get the details.

Please refer pass a value into next page

Community
  • 1
  • 1
Murtaza
  • 3,045
  • 2
  • 25
  • 39