Reputation: 196469
I have the following goal:
I Have a list of top menu links on my website
Home * Links * Quotes * Photos
The only difference is that whenever you are on a particular page, I want that page to just be text (not a href link) and the others to be links (to show that this is the page you are on):
i got this working but it seems very bad way of doing it and i am looking for a better way of doing this:
in my master page, i have the following:
<asp:ContentPlaceHolder runat="server" ID="TopMenuLinks">
</asp:ContentPlaceHolder>
In each individual separate page, i have the following (this is the Family Tree Example):
Family Tree would look like this:
<asp:Content ID="Content3" ContentPlaceHolderID="TopMenuLinks" runat="server">
<a href="http://xxx/albums.aspx">Photos</a> -
<a href="http://xxx/globe.aspx">Travel</a> -
Family Tree
<a href="http://xxx/wiki.aspx"><spanstyle="color:"#000088">Wiki</span></a> -
<a href="http://xxx/blog.aspx"><span style="color:"#000088">Baby Blog</span></a>
</asp:Content>
Photos would look like this:
<asp:Content ID="Content3" ContentPlaceHolderID="TopMenuLinks" runat="server">
Photos -
<a href="http://xxx/globe.aspx">Travel</a> -
<a href="http://xxx/globe.aspx">Family Tree</a> -
<a href="http://xxx/wiki.aspx"><spanstyle="color:"#000088">Wiki</span></a> -
<a href="http://xxx/blog.aspx"><span style="color:"#000088">Baby Blog</span></a>
</asp:Content>
So as you can see, in each page i essentially have duplicate code with that particular page not as a link.
Is there any cleaner way of doing this without duplicating a lot of this code on everyone of my pages?
the way i am
Upvotes: 0
Views: 349
Reputation: 73564
I did the same thing using a master page, using ASP:Hyperlink controls. In the code behind on the master page I had code to set the NavigateUrl to en empty string if the NavigateUrl matched the location of the child page.
It results in the effect you're looking for.
Upvotes: 2
Reputation: 373
Create a UserControl for your common code and add a reference to each page. You could expose a Bool property on the control to either render hyperlinks or plain text and set that property as you need on each page.
Upvotes: 0