QueryString to pass values from page to another page.

So times we need to pass the values from one page to other page., For this requirement we

had some options. In those Query string is one of the best option.



By using Query string we can pass data from one page another without based on source and

target pages of the application.

We can pass information between pages in various ways, some of which depend on how the

redirection occurs. The following QueryString option is available even if the source page

is in a different ASP.NET Web application from the target page, or if the source page is

not an ASP.NET Web page.

The Normal url will be like this http://deliciousdotnet/mypage.aspx

But when it comes to query string url the url will be like the following
http://deliciousdotnet/mypage.aspx?Val=value1
http://contoso.com/products.aspx?field1=value1&field2=value2
We will pass the value from our current page to the destinaltion like.,
string Val = "Hello";
           Response.Redirect("http://deliciousdotnet/mypage.aspx?Val="+val);
Now you can access this value in the mypage.aspx.cs in page_Load event or in any method like

this,

String Val = Request.QueryString["Val"];
Now we can use this value in our page as we wish.

See you again.

Share it

3 comments:

  • Lizlsizl said... May 30, 2013 at 5:23 AM

    I was wondering if this solution still works if the user visits other pages and then goes back to the destination page?
    ie. original link with query string http://deliciousdotnet/mypage.aspx?Val=value1
    goes to mypage.aspx
    then goes to randompage.aspx
    then goes back to mypage.aspx
    Will the value from the query string travel through that journey?

  • Lizlsizl said... May 30, 2013 at 5:23 AM

    I was wondering if this solution still works if the user visits other pages and then goes back to the destination page?
    ie. original link with query string http://deliciousdotnet/mypage.aspx?Val=value1
    goes to mypage.aspx
    then goes to randompage.aspx
    then goes back to mypage.aspx
    Will the value from the query string travel through that journey?

  • Lizlsizl said... May 30, 2013 at 5:24 AM

    I was wondering if this solution still works if the user visits other pages and then goes back to the destination page?
    ie. original link with query string http://deliciousdotnet/mypage.aspx?Val=value1
    goes to mypage.aspx
    then goes to randompage.aspx
    then goes back to mypage.aspx
    Will the value from the query string travel through that journey?

Post a Comment