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?

1
  • this is the reason for down votes of your previous question. Commented Jun 27, 2012 at 11:29

4 Answers 4

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"]);
Sign up to request clarification or add additional context in comments.

Comments

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"];
    }

1 Comment

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!
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"]);

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.