X



Home>Tutorial>

Best Top 6 ASP.Net Page Navigation Techniques

Nuelson Penuel Friday, August 28, 2020 Article

Summary

In this article, we will learn different techniques that are used for page navigation in ASP.net.

What is ASP.Net Page Navigation?

Page navigation is a navigational technique used for moving from one webform to another in asp.net.

Various ASP.Net Navigation Techniques

There are several ways for page navigation and they are outlined as follows; 1. Server.Transfer 2. Response.Redirect 3. Cross-Page Postback 4. Server.Execute 5. Window.Open 6. Hyperlink control

Server.Transfer

Server.Transfer is used to navigate to other pages or sites running on the same web server.

Server.Transfer Syntax

Server.Transfer(path)
Where path refers to the location of the file to which control should be transfered

Characteristics of Server.Transfer

1. It does not navigate to sites/pages that are outside the web server 2. Its URL remains unchanged in the address bar 3. The form variables from original request page are retained. 4. It is faster than Response.Redirect as the redirection happens on the server in one request/response cycle.

Server.Execute

When Server.Execute method is used, the path to the destination page is passed to the Server.Execute Method as a parameter and the control moves to this new page. However, execution of code happens on the new page and once code execution on the destination page is over, the control returns to the initial page, just after where it was called.

Server.Execute Syntax

Server.Execute(path)
Where path refers to the location of the requested page

Characteristics of Server.Execute

1. It does not navigate to sites/pages that are outside the web server 2. Its URL remains unchanged in the address bar 3. The form variables from original request page are retained. 4. It is faster than Response.Redirect as the redirection happens on the server in one request/response cycle. If you noticed, Server.Transfer and Server.Execute url shares the same characteristics. The only difference is;

Diffrence Between Server.Transfer and Server.Execute

The difference between Server.Transfer and Server.Execute is; Server.Transfer will stop the execution of the current page and proceed imnediately to execution of the new requested page. While; Server.Execute process the second webform without terminating the first Web form. However, after the complete execution of the first page the control returns to second page.

Response.Redirect

The Response.Redirect() method is used to redirect a user from one page to another and also letting the user know that you have been redirected from your current page to another.

Response.Redirect Syntax

It has the following syntax;
Response.Redirect(path)
Where path refers to the destination file that is requested by the client.

Characteristics of Response.Redirect

1. When the user clicks a redirect button, the webserver receives, a request for redirection. 2. The server then sends a response header to the client. 3. Then the client browser automatically issues a new GET request to the web server. 4. The web server will then serve the new page. Note: Response.Redirect causes 2 request/response cycles.

Cross-Page Postback

By default, when you as a user click a button on a asp.net web form where Response.Redirect is not used on the codebehind, or PostBackUrl attribute value is not specified, the webform will postback to itself. So If you as a developer want the user to be posted to another webform on a button clcik, you have to set the PostBackUrl of the button to the page that you want to post to.

Cross-Page PostBack Syntax

If Page.IsPostBack Then

'Code to execute
       Else
'Code to execute
End If

Characteristics of Cross-Page Postback

1. Page.IsCrossPagePostBack property is used to indicate whether the page is involved in a cross-page postback 2. It sends the post to another page if PostBackUrl is specified

Hyperlink Control

The Hyperlink control displays a HTML link to an address, which opens in the default browser for the computer. Links are not supported for protocols other than HTML. The page you want to navigate to is specified using NavigateURL property. Using hyperlink, you can navigate to another page within same or outside the application or even to external website. The hyperlink control is rendered as an HTML anchor <a> tag. The Hyperlink control does not expose any server side events, so when the user clicks on a hyperlink there is no server side event to intercept the click.

Hyperlink Control Syntax

<asp:HyperLink id="hyperlink1" NavigateUrl="#" Text="" runrunaterver"/> 

Hyperlink Control Characteristics

1. NavigateURL property can be hardcoded 2. NavigateURL can also be changed dynamically from codebehind

Window.Open

Window.Open Syntax

window.open(URL,name,specs,replace)

Characteristics of Window.Open

1. The open() method opens a new browser window. 2.The Close() method is needed to close the windows 3. The open() is supported in all major browsers like chrome,safari,opera,IE

Window.Open Parameters, Description and Broswers Support

  1. URL(Optional)-: Specifies the URL of the page to open. If no URL is specified, a new window with about:blank is opened
  2. name(Optional)-: Specifies the target attribute or the name of the window. The following values are supported: _blank: URL is loaded into a new window. This is default _parent: URL is loaded into the parent frame _self: URL replaces the current page _top: URL replaces any framesets that may be loaded name: The name of the window (Note: the name does not specify the title of the new window)
  3. specs (Optional)-: A comma-separated list of items. The following values are supported: channelmode=yes|no|1|0 Whether or not to display the window in theater mode. Default is no. IE only directories=yes|no|1|0 Obsolete. Whether or not to add directory buttons. Default is yes. IE only fullscreen=yes|no|1|0 Whether or not to display the browser in full-screen mode. Default is no. A window in full-screen mode must also be in theater mode. IE only height=pixels. The height of the window. Minimum value is 100 left=pixels. The left position of the window. Negative values not allowed location=yes|no|1|0 Whether or not to display the address field. Opera only menubar=yes|no|1|0 Whether or not to display the menu bar resizable=yes|no|1|0 Whether or not the window is resizable. IE only scrollbars=yes|no|1|0 Whether or not to display scroll bars. IE, Firefox & Opera only status=yes|no|1|0 Whether or not to add a status bar titlebar=yes|no|1|0 Whether or not to display the title bar. Ignored unless the calling application is an HTML Application or a trusted dialog box toolbar=yes|no|1|0 Whether or not to display the browser toolbar. IE and Firefox only top=pixels The top position of the window. Negative values not allowed width=pixels The width of the window. Min. value is 100
  4. replace (Optional)-: Specifies whether the URL creates a new entry or replaces the current entry in the history list. The following values are supported: true – URL replaces the current document in the history list false – URL creates a new entry in the history list

| | Views(945)

See Demo | Download File


Add your comment. Indicate code using code tag


Words: 0 | Chars: 0 | Reading Duration: 0



Images Attachment




Emmason Integratded Services(2017-2024)
All Rights Reserved
Designed and Maintained By Emmason Integrated Services