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?
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"]);
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"];
}
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"]);
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.