-4

Possible Duplicate:
How can I pass values from one form to another in Asp.net

Hi.

I want to pass some data from one page to another at asp.net how can I do this in asp.net?

Community
  • 1
  • 1
calypso
  • 19
  • 1
  • 1
  • 5
  • I cannot understand why are you decreasing my rep? – calypso Jun 27 '12 at 09:16
  • Because while asking a question on stackoverflow you should do some basic search about your problem and if you don't find any solution, then you have to ask here. Asking similar questions which are already there in stackoverflow leads to the waste of time. – Ranadheer Reddy Jun 27 '12 at 11:26

1 Answers1

4

You can use the QueryString, Session, or Cookies

Note. In all cases when reading the value from the corresponding collection, you need to validate if the object exists before consuming it. (check for null)

Using the query string

Page 1

<a href="mysecondPage.aspx?customerID=43" >My Link</a>

Page 2

    protected void Page_Load(object sender, EventArgs e)
    {
        var c = this.Request.QueryString["customerID"];
    }

Using the Session object

Page 1

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Session["customerID"] = 44;
    }

Page 2

    protected void Page_Load(object sender, EventArgs e)
    {
        var c = (int)this.Session["customerID"];
    }

Using cookies

Page 1

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Response.Cookies["customerID"].Value = "43";
    }

Page 2

    protected void Page_Load(object sender, EventArgs e)
    {
        var c = int.Parse(this.Request.Cookies["customerID"].Value);
    }
Jupaol
  • 21,107
  • 8
  • 68
  • 100