http://www.localhost.com/Webform.aspx?name=asp&article=framework
This html addresses use QueryString property to pass values between pages.
Disadvantages of this approach
- QueryString have a max length, If you have to send a lot information this approach does not work.
- QueryString is visible in your address part of your browser so you should not use it with sensitive information.
- QueryString can not be used to send & and space characters.
private void btnSubmit_Click(object sender, System.EventArgs e)
{
string p1 = this.txtName.Text.Replace("&","%26");
p1 = this.txtName.Text.Replace(" ","%20");
string p2 = this.txtArticle.Text.Replace("&","%26");
p2 = this.txtArticle.Text.Replace(" ","%20");
string redirectweb= "WebForm.aspx?" + "Name=" + p1 + "&Article=" + p2;
Response.Redirect(redirectweb);
}
Since this is a such a common problem Asp.Net should have some way to solve. There it is Server.UrlEncode. Server.UrlEncode method changes your query strings to so that they will not create problems.
private void btnSubmit_Click(object sender, System.EventArgs e)
{
Response.Redirect("WebForm.Aspx?" +
"Name=" + Server.UrlEncode(this.txtName.Text) +
"&Article=" + Server.UrlEncode(this.txtArticle.Text));
}