0

I want to pass more than one variable to other web pages.

I try this code

string adi = TaskGridView.SelectedRow.Cells[3].Text;

string soyadi = TaskGridView.SelectedRow.Cells[3].Text;

Response.Redirect("Default2.aspx?adi=" + adi);

Response.Redirect("Default2.aspx?soyadi=" + adi);

but it doesnt work how can I do?

Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
calypso
  • 19
  • 1
  • 1
  • 5

4 Answers4

4

The safest way is to use String.Format() with Server.UrlEncode():

Response.Redirect(String.Format("Default2.aspx?adi={0}&soyadi={1}", Server.UrlEncode(adi), Server.UrlEncode(soyadi)));

This will ensure that the querystring values will not be broken if there is an ampersand (&) for example, in the value.

Then on Default2.aspx you can access the values like:

Server.UrlDecode(Request.QueryString["adi"]);
Curtis
  • 101,612
  • 66
  • 270
  • 352
1

Concatenate them like this:

Response.Redirect("Default2.aspx?adi=" + adi + "&soyadi=" + soyadi);

When passing query string parameters, use the ? symbol just after the name of the page and if you want to add more than one parameter, use the & symbol to separate them

In the consuming page:

    protected void Page_Load(object sender, EventArgs e)
    {
        var adi = this.Request.QueryString["adi"];
        var soyadi = this.Request.QueryString["soyadi"];
    }
Jupaol
  • 21,107
  • 8
  • 68
  • 100
  • 2
    please see @curt's reply below. it is more secure and a more recommended way of achieving the same thing. the security implications of this are important! – Andrew Jun 27 '12 at 10:23
0

You can also use the session to pass values from one page to another

Set the values in the page where you want to pass the values from in to a session

Session["adi"] = TaskGridView.SelectedRow.Cells[3].Text;

Session["soyadi"] = TaskGridView.SelectedRow.Cells[3].Text;

In the Page where you want to retrieve- You do like this..

string adi=(string)(Session["adi"]);
string soyadi=(string)(Session["soyadi"]);
Hari Gillala
  • 11,736
  • 18
  • 70
  • 117
0

You can as well pass values through ViewState or Session the diffrent with what you doing now is: People will not see anything in your url and have no idea what happend in backend. It's good when you passing some "topsecret" data ;P

Harry89pl
  • 2,415
  • 12
  • 42
  • 63