tags:

views:

103

answers:

2

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"&gt;Photos&lt;/a&gt; &nbsp;&nbsp;-&nbsp;
 <a href="http://xxx/globe.aspx"&gt;Travel&lt;/a&gt; &nbsp;&nbsp;-                
 Family Tree
 <a href="http://xxx/wiki.aspx"&gt;&lt;spanstyle="color:"#000088"&gt;Wiki&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;-
 <a href="http://xxx/blog.aspx"&gt;&lt;span style="color:"#000088">Baby Blog</span></a>
</asp:Content>

Photos would look like this:

<asp:Content ID="Content3" ContentPlaceHolderID="TopMenuLinks" runat="server">
 Photos &nbsp;&nbsp;-&nbsp;
 <a href="http://xxx/globe.aspx"&gt;Travel&lt;/a&gt; &nbsp;&nbsp;-                
 <a href="http://xxx/globe.aspx"&gt;Family Tree</a> &nbsp;&nbsp;-                
 <a href="http://xxx/wiki.aspx"&gt;&lt;spanstyle="color:"#000088"&gt;Wiki&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;-
 <a href="http://xxx/blog.aspx"&gt;&lt;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

A: 

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.

canice
+1  A: 

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.

David Stratton