Page navigation is the process of moving from one page to
another page in your website. There are many ways to navigate from one page to
another in ASP.NET.
The HyperLink control is used to create a link to another Web page. The Text
property is used for displaying the text in the HyperLink. We can also display
a image on this control instead of text. To display an image we should set the
ImageUrl property.
You can also use JavaScript for client side navigation. You should use HTML
input button for this.
Example:
function Button1_onclick()
{
document.location="WelcomePage.aspx";
}
2. Cross-page posting
By default, buttons and other controls that cause a postback on an ASP.NET Web
page submit the page back to itself. ASP.Net provides a feature known as Cross
Page PostBack that enables a web form to post-back to a different web form. The
Page class has a property named PreviousPage. If the source page and target
page are in the same ASP.NET application, the PreviousPage property in the
target page contains a reference to the source page.
Example:
We have two web pages named Home.aspx and Welcome.aspx respectively. The first
page contains a Button and a Textbox. Button control that has its PostBackUrl
property set to “~/Welcome.aspx”
// Sample code for Welcome.aspx.
if (Page.PreviousPage != null)
{
TextBox MyTextBox = (TextBox)Page.PreviousPage.FindControl("TextBox1");
if (MyTextBox!= null)
{
Label1.Text = MyTextBox.Text;
}
}
3. Client-side browser redirect
The Page. Response object has redirect method. The Redirect method can be used
in your server-side code to instruct the browser to initiate a request for
another Web page. The redirect is not a PostBack. It is similar to the user
clicking a hyperlink on a Web page.
The Transfer method transfers all the state information in one ASP .NET Page to
a second ASP.NET Page. Server.Transfer changes the page being rendered on the
browser. This happens all on the server. A redirect is not issued to the web
browser.