Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Getting the URL of the previous page in Macro or Transformation? View modes: 
User avatar
Member
Member
Armysniper89 - 10/25/2011 12:02:32 AM
   
Getting the URL of the previous page in Macro or Transformation?
In my transformation I have to build, I need to provide a link to the previous page that the user was on before coming to the page where my transformation is being displayed. I am trying to get back to the page where the custom table repeater or link was that got to the details page my transformation is displaying...

Is there a way in the transform to get the URL of the previous page? If not can I get it through macro code in say a web part container?

User avatar
Member
Member
kentico_michal - 10/25/2011 7:01:33 AM
   
RE:Getting the URL of the previous page in Macro or Transformation?
Hello,

Regrettably, no transformation method that returns a link to previous page is available. You could create a custom transformation method and get the previous page using the UrlReferrer property:

Uri referrer = HttpContext.Current.Request.UrlReferrer;

For more information about custom transformation method I would like to point you to the following article:
Adding custom functions to transformations

in case of the web part container property, you can create a custom macro instead:
Types of macros

Best regards,
Michal Legen

User avatar
Member
Member
Armysniper89 - 10/25/2011 2:33:15 PM
   
RE:Getting the URL of the previous page in Macro or Transformation?
I solved the problem after I wrote the question...here is how I did it...in the transformation (which is where the link exists that I want to set the Href for), I added some code like this:

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
// Find the server name on the previous page
string previousPageURL = Request.UrlReferrer.ToString();
System.Web.UI.HtmlControls.HtmlAnchor topAnchor = (System.Web.UI.HtmlControls.HtmlAnchor)FindControl("backToResultsTop");
System.Web.UI.HtmlControls.HtmlAnchor bottomAnchor = (System.Web.UI.HtmlControls.HtmlAnchor)FindControl("backToResultsBottom");

if (!string.IsNullOrEmpty(previousPageURL))
{
topAnchor.HRef = previousPageURL;
bottomAnchor.HRef = previousPageURL;
}
else
{
topAnchor.HRef = "~/Calendars.aspx";
bottomAnchor.HRef = "~/Calendars.aspx";
}
}
</script>


I had a bottom and a top link that did the same, thus the two settings for the bottom and top anchor tags. :) Works like a charm. Might want to add some logic to avoid external referals from breaking things but otherwise using some inline code worked.