Saturday, March 5, 2011

Different navigation Techniques for Aspnet Developers

Hi Freinds ,In this Article we will discuss a different navgination techniques which is very useful in our web applications.
Already i discussed in my previous post how to open different page in one hyper link Click Here
 now i am going to discuss about different navigation techniques
Navigation with Hyperlinks :



The simplest way to link two pages together is with a hyperlink.
In ASP.NET, you have several choices for creating a hyperlink, including the following:

As a non-server control using an HTML <a> element

As a server control by adding the runat="server" attribute to an HTML <a> element

Using an ASP.NET Hyperlink control

Using an ASP.NET LinkButton control

Using one of the more complex ASP.NET server controls that creates links

Simple way to define a Hyperlink with html anchor tag

<a href="nextpage.aspx">Click me to go next page</a>

To implement a hyperlink that acts as an anchor at a specific position within the page, you use the Name property,

Creating a Hyperlink and Anchor using the HtmlAnchor Control

<a id="MyHyperlink" runat="server" href="#para1"  title="paragraph 1">go to Paragraph 1 in the page</a>

<a id="MyAnchor" runat="server" name="para1">This is Paragraph 1</a>

If the target anchor is within another page, we simply include the URL of that page in the HRef attribute:
<a id="MyHyperlink" runat="server" href="page2.aspx#para1">...</a>
Image with HtmlAnchor Control :

We can place other controls within the <a> element.
Such as when we want to clickableimage that causes navigation to another page .just add this code

<a id="MyHyperlink" runat="server" href="page2.aspx" title="Go to page 2">
  <img src="picture1.gif" alt="Go to page 2" border="0"/>
</a>


The ASP.NET Hyperlink Control
ASP.NET includes the Hyperlink control, which provides a much more structured and simpler approach to generating hyperlinks of all kinds.

To generate a simple hyperlink, you just need this:
<asp:Hyperlink id="MyFirstLink" runat="server" NavigateUrl="Firstpage.aspx" Text="Click ME" />

Using Access Keys
ASP.NET provide the AccessKey property, where we can use to implement shortcut access to that control.
You set the AccessKey property to a single-character string that is the key the user will press in conjunction with the Alt key to move the input focus to that control.
 Example :
<asp:Hyperlink id="MyFirstLink" runat="server" AccessKey="Q" NavigateUrl="Firstpage.aspx" Text="Click Me" />
this Hyperlink control that receives the input focus if the user presses Alt+Q then the page is displayed



Navigation through Browser Redirection :

Navigation consists of pointing the browser to a specific page in response to user interaction. The Hyperlink control, and various other complex controls that generate hyperlinks, cause the browser to load the specified page when the user clicks that link. However, you can force the browser to load a different page by sending back an "Object Moved" HTTP header that contains the new URL of the requested resource.

simple example :
Response.Clear();
Response.Redirect("http://www.myFirstsite.com/Homepage.aspx");
Response.End();

Redirection with Client-Side Script :
We can navigate the page by using client-side script that runs in the browser
All that is required is to set the window.location.href property in client-side script to the required URL,and the browser automatically loads from that URL.
Dont forget to remember to return false from the client-side function to ensure that no postback occurs.

 Client-Side Redirection with JavaScript Code
<script language="javascript"
<!-
function ClientSideNavigation()
{
  window.location.href = 'theHomepage.aspx';
  return false;
}
//->
</script>

<asp:Button id="Button1" runat="server" Text="Redirect" OnClientClick="return ClientSideNavigation()" />

Navigation through Server-Side Redirection:
we can perform two types of server-side redirection:
Transfer to another page (where execution ends at the end of that page), or execution of another page (where control returns to the original page when the second page completes its execution).
 ASP.NET provides two methods to support this feature. The transfer method of the HttpServerUtility class performs transfer to another page, and the Execute method causes execution of the second page.

The HttpServerUtility.Transfer Method

The transfer method has three overloads. The first simply takes the URL of the page to execute.
Server.Transfer("url")

By default, the contents of the Form and QueryString collections are available in the target page of the transfer.

Server.Transfer("url", [true | false])

Finally, you can also execute a class that implements the IHttpHandler interface, which is useful if you write your own HTTP handler.
 This overload also takes a second parameter that determines if the Request collections are preserved.
Server.Transfer(handler-class, [true | false])

developercode
About the Author
Sayyad is a Software Engineer, Blogger and Founder of Developers Code from India.His articles mainly focus on .Net (Web and Windows based applications), Mobile Technologies (Android,IPhone,BlackBerry) and SEO.

Labels: , , , ,

4 Comments:

At March 8, 2011 at 5:15 PM , Blogger Dotnet Tutorials said...

Hey thanks to share this........

 
At April 20, 2011 at 5:53 PM , Anonymous Anonymous said...

Nice post..

 
At April 20, 2011 at 5:54 PM , Anonymous Anonymous said...

Good One dude......

 
At June 28, 2011 at 10:17 AM , Anonymous Anonymous said...

Good One dude......

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home