Navigation and query string in Asp.net

Navigation and query string in Asp.net

As we know, the moving from one page to another is not that the hard task for any one, but there are some facts and important terms which makes us study the ‘navigation’ in ASP.net. Basically the Page navigation actually means that, to move or jump from one page to another. This navigation may be within the same site or to the other sites.

In ASP.net, you have two ways to move from one page to another page. You can do this with the help of hyperlinks and the command like Response. Redirect (“page path”). Let us start with the hyperlinks: - These are the simplest and the easiest way which allows you to navigate between two different pages. This is the basic html control mostly used by us. The basic syntax for that is,

<a href="webform.aspx">page</a>

And the same can be done with the asp.net server tags, and the syntax for that is given below:-

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="webpage.aspx">HyperLink</asp:HyperLink>

Asp.net hyperlink has the same effect as the html hyperlink. The only difference between them is that the asp.net hyperlinks are the server control. And, as this is a server control, you will get all the events to handle the hyperlinks.

Response. Redirect ();

Response. Redirect() is the another way to navigate between different webpage. It helps a lot to control the navigation, when we want to redirect the user from one page to another without the user’s permission, where user does not need to click any hyperlink to navigate. This helps to get connected to different webpage. When the response.redirect method is called, then it creates a header response. As header response reaches to the client from the server, this header information generates the HTTP request to the new URL.

Passing variable from one page to another using hyperlink or response redirect method

You usually need to pass variable from one aspx page to another aspx page, you can use hypertext with the query string. Query string is the most often used method to pass the value from one page to another. To pass the value using query string you can associate them with the page URL which has been shown as follows.


In this URL you are passing three things, first the web address Webform2.aspx, an id having value of 10 and the name which can be anything. The question mark (?) is used to start the query string and (&) is always used between the variable passed between the pages. And on the other page you can receive the variable using the Respone.redirect() method.

You can write the syntax as follows for the request redirect method:


This will get the value given here as “anything”.

The query string has some limitations, that, it has a fixed length. If we send a lot of values, then it may be possible that in this case, this approach doesn’t work. As the query string is visible in the URL so never use this method for the sensitive data like password or other valuable information. We can never pass a “space” and the “&” symbol through query string because it replaces the ‘space’ with ‘%20’ and replace the ‘&’ symbol with ‘%25’.