Solved

Help with Menu Control in ASP.net

Posted on 2006-06-21
5
1,322 Views
Last Modified: 2010-07-27
I have created a menu control for site navagation on my web page.  I have given it a width of 150px.  I also applied an Auto Format so it would have mouse over functions, etc.  The problem is that you have to click on the Menu Item Text for your hyperlink to work.  Becuase my menu has a width of 150px, I have empty space to the right of most of my link descriptions.  But when you roll the mouse the select menu item background changes as it should.  But if you don't mouse click on the text, then the menu doesn't work.  

How can I insure that the link will work if they click anywhere within the menu item region?

Thanks!!!
0
Comment
Question by:accmats
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:gregg1ep00
ID: 16953158
You can use the <StaticItemTemplate> and <DynamicItemTemplate> to do something like this:

<asp:Menu ID="mnu" runat="server" Orientation="horizontal">
      <StaticItemTemplate>
            <div
            onclick="window.navigate('<%# ResolveUrl( (string) Eval("NavigateUrl") ) %>')">
                  <asp:HyperLink
                  ID="lnk"
                  runat="server"
                  Text='<%# Eval("Text") %>'
                  NavigateUrl='<%# Eval("NavigateUrl") %>' />
            </div>
      </StaticItemTemplate>
      <DynamicItemTemplate>
            <div
            onclick="window.navigate('<%# ResolveUrl( (string) Eval("NavigateUrl") ) %>')">
                  <asp:HyperLink
                  ID="lnk"
                  runat="server"
                  Text='<%# Eval("Text") %>'
                  NavigateUrl='<%# Eval("NavigateUrl") %>' />
            </div>
      </DynamicItemTemplate>
</asp:Menu>
0
 
LVL 4

Expert Comment

by:gregg1ep00
ID: 16953238
Actually, it's working on my system without all the javascript stuff in the client-side onclick handler.  So it looks like the javascript stuff is unnecessary.

<asp:Menu ID="mnu" runat="server" Orientation="horizontal">
      <StaticItemTemplate>
            <div
            style="width:150px;">
                  <asp:HyperLink
                  ID="lnk"
                  runat="server"
                  Text='<%# Eval("Text") %>'
                  NavigateUrl='<%# Eval("NavigateUrl") %>' />
            </div>
      </StaticItemTemplate>
      <DynamicItemTemplate>
            <div
            style="width:150px;">
                  <asp:HyperLink
                  ID="lnk"
                  runat="server"
                  Text='<%# Eval("Text") %>'
                  NavigateUrl='<%# Eval("NavigateUrl") %>' />
            </div>
      </DynamicItemTemplate>
</asp:Menu>
0
 

Author Comment

by:accmats
ID: 16956879
Thanks for your reply.  That worked but is there a way to keep the text from looking like a hyperlink and taking on hyperlink type styles like being underlined and hyperlinked font color?

Thanks for all your help!
0
 
LVL 4

Accepted Solution

by:
gregg1ep00 earned 250 total points
ID: 16956998
You can do that with CSS.  The rule you want to use is:

.MenuItem a,
.MenuItem span
{
   text-decoration: none;
   color: black;
}

.MenuItem .Hover a,
.MenuItem .Hover span
{
   text-decoration: none;
   color: white;
}

Of course, you'll want to adapt this to the CSS you already have for your <asp:Menu> control.  If you're not using any CSS stylesheets, you can use inline styles like this:
<asp:Menu ID="mnu" runat="server" Orientation="horizontal">
     <StaticItemTemplate>
          <div
          style="width:150px;">
               <asp:HyperLink
               ID="lnk"
               runat="server"
               Text='<%# Eval("Text") %>'
               NavigateUrl='<%# Eval("NavigateUrl") %>'
               ForeColor="black"
               Font-Underline="false" />
          </div>
     </StaticItemTemplate>
     <DynamicItemTemplate>
          <div
          style="width:150px;">
               <asp:HyperLink
               ID="lnk"
               runat="server"
               Text='<%# Eval("Text") %>'
               NavigateUrl='<%# Eval("NavigateUrl") %>'
               ForeColor="black"
               Font-Underline="false" />
          </div>
     </DynamicItemTemplate>
</asp:Menu>


Hope that helps!  ;)
0
 

Author Comment

by:accmats
ID: 16960314
Awsome answer.  Thanks for all your help.  I have added an additional question that is related to this one if you think you might can answer it.  THANKS AGAIN!

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21895574.html
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question