Wednesday, June 25, 2008

Relative Url in MasterPage with SPUrl

Tonight I was working on how to find relative url in Master Page. There was a link in the master page say ImportWizard.aspx. When user is in default.aspx the link was to ImportWizard.aspx. But when user moves to another page say Lists/Tasks/AllItems.aspx then the link is shown as Lists/Tasks/ImportWizard.aspx which is incorrect. So the link is built with current link is added to in front of ImportWizard.aspx. To resolve the problem all I needed was to make the link with respect to current site url rather than current location url. So I thought there may be an built in literal like ~SiteUrl which represents the current site url. But later I have found how to implement it. The way to implement it is

<a href="<% $SPUrl:~Site/ImportWizard.aspx %>" runat="server" >Import Wizard</a>

Here with which I faced problem is I had not added runat="server". If you don't add runat="server" then you'll seee an exception showing a message like "you should use literal control....."

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.