Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I transfer simple parameter from one ASP.Net page to another?

Tags:

asp.net

In the course I'm taking they taught me to use Response.Redirect like this:

Response.Redirect(string.Format("name.aspx?sb="+bts+"&del="+delimiter));

Is there a better way to do so?

like image 559
DaliH Avatar asked Dec 06 '25 04:12

DaliH


2 Answers

Specifically what you are discussing is the means to transfer state between pages. That can be done in an handful of ways:

  1. Query string parameters. This is the equivalent of what you have done in your post.
  2. Session. In this scenario, you would populate a Session variable on one page and then retrieve it on the other.
  3. Cookies.
  4. Form variables if you post directly to the page in question.
like image 171
Thomas Avatar answered Dec 11 '25 15:12

Thomas


See How to: Pass Values Between ASP.NET Web Pages.

In addition you can also use the HttpContext.Current.Items collection to pass data if you are performing a Server.Transfer instead of a Response.Redirect.

Also, the code snippet:

  • Is just performing string concatenation so you don't need to call string.Format.

  • Should UrlEncode query string parameters

e.g.

Response.Redirect("name.aspx?sb=" + Server.UrlEncode(bts) 
    + "&del=" + Server.UrlEncode(delimiter));
like image 23
Randy supports Monica Avatar answered Dec 11 '25 17:12

Randy supports Monica