Links and redirects

From RPM Wiki

Table of contents

Summary

Links and redirects are how users presented with different RPM pages. No matter what method is used, the basic mechanism is to give the client browser a URL and an instruction to load that page.

Options

There are a few different ways to serve the URL and different ways we can tell the browser to use it. First some terminology:

  • Originating page: The page the link is on
  • Destination page: The page the user ends up at

Code location

  • HTML: A link with the destination URL contained in the "href" attribute.
    • The URL can still be completely or partially dynamically generated by using an inline tag within a static control or by setting the href attribute on a server control.
  • Code behind: A "Response.Write" with JavaScript code that contains the URL.

Target

  • Frameset: This loads the destination page through the "Default.aspx" RPM frameset. The URL is shown in the browser address field.
  • Main frame: The destination page is loaded in the main frame without reloaded the frameset and thus not changing the URL the user sees.

History

  • Standard: This is a normal link so the originating page enters the browser's history.
  • Replace: This method loads a new page without adding a history entry.
    • This means navigating "Back" from the new page will go back to the page that was before the originating page.

Go

There is one completely different way to do a link. It invokes the JavaScript history.go function and replicates the user clicking "Back".

What to use

Which combination of options to use will depend on the situation. However, there are some basic guidelines that will define nearly every situation. Most RPM pages can be divided into two categories:

  • Display pages: These pages primarily contain information and links.
    • Examples: Home, Comm month, Agencies, Customer
  • Input pages: These pages are for the user to input data or otherwise complete some wizard.
    • Examples: Add a rep, Edit info

Code location

  1. HTML static: The best option is to use a regular, static link.
  2. HTML dynamic: If that can't be done because the URL is dynamic, use a hyperlink server control and set the href attribute in the code behind or a static anchor tag with an inline bind for the href attribute. Do whatever is needed for the situation.
  3. Code behind: It's the least desirable, but sometimes we just have to generate a script tag in the code behind. Like for button postback events.

Options

From To Target History
Display page Display page Frameset Standard
Input page Display page Frameset Replace
any Input page Main frame Standard

Go

The history.go may be used in certain situations when the best option for the user it to click back but we don't necessarily know the URL they were at.

  • Example: The default error page.

How to

  • The static destination is MyPage.aspx?Item=1
  • The dynamic destination is the above URL except with an item value defined by a variable in the code behind.
  • The destination for the history.go examples is unknown

HTML static, frameset, standard

<a href="../?Page=MyPage.aspx&Item=1" target="_top">My link</a>

HTML static, frameset, replace

<a href="javascript:window.top.location.replace('../?Page=MyPage.aspx&Item=1');">My link</a>

HTML static, main frame, standard

<a href="MyPage.aspx?Item=1">My link</a>

HTML static, main frame, replace

<a href="javascript:window.location.replace('MyPage.aspx?Item=1">My link</a>

HTML static, go

<a href="javascript:history.go(-1);">Back</a>

asp:HyperLink, frameset, standard

<asp:HyperLink ID="myLink" runat="server" Target="_top">My link</asp:HyperLink>

myLink.attributes["href"] = "../?Page=MyPage.aspx&Item=" + itemNumber;

asp:HyperLink, frameset, replace

<asp:HyperLink ID="myLink" runat="server">My link</asp:HyperLink>

myLink.href = "javascript:window.top.location.replace('../?Page=MyPage.aspx&Item=" + itemNumber + "');";

asp:HyperLink, main frame, standard

<asp:HyperLink ID="myLink" runat="server">My link</asp:HyperLink>

myLink.attributes["href"] = "MyPage.aspx?Item=" + itemNumber;

asp:HyperLink, main frame, replace

<asp:HyperLink ID="myLink" runat="server">My link</asp:HyperLink>

myLink.attributes["href"] = "javascript:window.location.replace('MyPage.aspx?Item=" + itemNumber + "');";

Response.Write, frameset, standard

Response.Write("<script>window.top.location.href = '../?Page=MyPage.aspx&Item=" + itemNumber +"';</script>");

Response.Write, frameset, replace

Response.Write("<script>window.top.location.replace('../?Page=MyPage.aspx&Item=" + itemNumber +"');</script>");

Response.Write, main frame, standard

Response.Write("<script>window.location.href = 'Page=MyPage.aspx?Item=" + itemNumber +"';</script>");

Response.Write, main frame, replace

Response.Write("<script>window.location.replace('Page=MyPage.aspx?Item=" + itemNumber +"');</script>");

Response.Write, go

Response.Write("<script>history.go(-1);</script>");

Target mistakes

In both these cases the JavaScript will detect the mistake and fix it by reloaded properly. That's undesirable as it uses time and resources for the reload and further some users may notice the reload as a sort of flash.

  • Load frameset in frame. This happens when Default.aspx is linked to without target="_top". With the redirect method that's by using window.location instead of window.top.location.
  • Load page without frameset. This happens when the aspx page is called without the frameset. The target="_top" but it's not Default.apsx that's the page. With the redirect method that's by using window.top.location instead of window.location.
  • This page was last modified 21:17, 6 Oct 2008.
  • This page has been accessed 1624 times.