Reputation: 19
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?
Upvotes: 0
Views: 19316
Reputation: 2435
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
Upvotes: 0
Reputation: 11926
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"]);
Upvotes: 0
Reputation: 103428
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"]);
Upvotes: 4
Reputation: 21365
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"];
}
Upvotes: 1