Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate url for href in aspx page

How does one generate a URL in a master page's ASPX page so that the reference works everywhere across the app?

Here is an example from a menu in a master page:

<a href="Admin/AddVendor.aspx">Add Vendor</a>

The problem is that if I leave the URL as it is on the master page, then when someone is already on a page that resides in the Admin folder, this URL no longer works. I need to path the URL from the root every time, but forget how to do this in WebForms.

like image 386
flying227 Avatar asked Feb 28 '14 14:02

flying227


People also ask

What is href =# in HTML?

Definition and UsageThe href attribute specifies the URL of the page the link goes to. If the href attribute is not present, the <a> tag will not be a hyperlink. Tip: You can use href="#top" or href="#" to link to the top of the current page!


1 Answers

Try using this, which maps to your website's root directory:

<a href="/Admin/AddVendor.aspx">Add Vendor</a>

EDIT : In that case, you could do this:

<a href="<%= Page.ResolveUrl("~/Admin/AddVendor.aspx") %>">Add Vendor</a>

It would be far easier to just use the asp.net Hyperlink control though

<asp:HyperLink ID="Link1" runat="server" NavigateUrl="~/Admin/AddVendor.aspx" Text="Add Vendor" />
like image 193
JW Lim Avatar answered Oct 14 '22 19:10

JW Lim