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
.
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!
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With