asp menu

Posted on 2012-08-23
Last Modified: 2012-09-03
hey guys i am building a menu from data base

here my code

<asp:Menu ID="mnu" runat="server" MaximumDynamicDisplayLevels="10" CssSelectorClass="myMenu" Orientation="Horizontal" OnMenuItemClick="mnu_MenuItemClick">
                                        <asp:MenuItemBinding DataMember="MenuItem" TextField="Text" ToolTipField="ToolTip" NavigateUrlField="NavigateUrl" ValueField="Id" />

the problem i am having the when i populate a node NavigateUrl == "" they is a problem?

the click method on my menu keep refreshing my page when the url coloum in my table is null.

please help me change that to nothing if the NavigateUrl is empty to #

here my view source code of my page

<div class="myMenu" id="ctl00_mnu">
	<div class="AspNet-Menu-Horizontal">
			<ul class="sf-menu">
				<li class="sf-with-ul">
					<a href="javascript:__doPostBack('ctl00$mnu','b1')" class="sf-menu-link" title="PRODUCTS">
					<ul style="visibility:hidden; display:none;">
						<li class="sf-with-ul">
							<a href="javascript:__doPostBack('ctl00$mnu','b1\\2')" class="sf-menu-link" title="Industrial / Domestic Gases">
								Industrial / Domestic Gases</a>
							<ul style="visibility:hidden; display:none;">
								<li class="sf-leaf">
									<a href="javascript:__doPostBack('ctl00$mnu','b1\\2\\183')" class="sf-menu-link" title="Industrial Gases">
										Industrial Gases</a>
								<li class="sf-leaf">
									<a href="javascript:__doPostBack('ctl00$mnu','b1\\2\\184')" class="sf-menu-link" title="LP / Domestic Gases">
										LP / Domestic Gases</a>
						<li class="sf-with-ul">
							<a href="javascript:__doPostBack('ctl00$mnu','b1\\3')" class="sf-menu-link" title="Welding Machines / Torches /Spares">
								Welding Machines / Torches /Spares</a>
							<ul style="visibility:hidden; display:none;">
								<li class="sf-with-ul">
									<a href="javascript:__doPostBack('ctl00$mnu','b1\\3\\7')" class="sf-menu-link" title="MIG Welding Machines">
										MIG Welding Machines</a>
									<ul style="visibility:hidden; display:none;">
										<li class="sf-leaf">
											<a href="product.aspx?name=migmax-210-amp-/-220v-inverter-type&amp;category=mig-welding&amp;id=1" class="sf-menu-link" title="Migmax 210 amp / 220v Inverter type">
												Migmax 210 amp / 220v Inverter type</a>
										<li class="sf-leaf">
											<a href="product.aspx?name=migmax-255-/-220v-(inverter-type)&amp;category=mig-welding&amp;id=2" class="sf-menu-link" title="Migmax 255 / 220v (Inverter type)">
												Migmax 255 / 220v (Inverter type)</a>
										<li class="sf-leaf">
											<a href="product.aspx?name=mig-welder-250-amp-/-380v&amp;category=mig-welding&amp;id=3" class="sf-menu-link" title="Mig Welder 250 amp / 380v">
												Mig Welder 250 amp / 380v</a>
										<li class="sf-leaf">
											<a href="product.aspx?name=mac022a&amp;category=mig-welding&amp;id=4" class="sf-menu-link" title="MAC022A">
										<li class="sf-leaf">
											<a href="product.aspx?name=mac023&amp;category=mig-welding&amp;id=5" class="sf-menu-link" title="MAC023">
										<li class="sf-leaf">
											<a href="product.aspx?name=mac024&amp;category=mig-welding&amp;id=6" class="sf-menu-link" title="MAC024">
										<li class="sf-leaf">
											<a href="product.aspx?name=mac032&amp;category=mig-welding&amp;id=7" class="sf-menu-link" title="MAC032">

Open in new window

Question by:JCWEBHOST
    LVL 15

    Expert Comment


    While you retrieve from the Database, just make the null values to # like...

    Select Isnull(NavigateUrl, '#') from tablename


    Author Comment

    i tried that

    select id, parent_id, title ,Isnull(url, '~/#') from menu

    but none of my links are working
    LVL 23

    Accepted Solution


    You can achieve it with simple jQuery snippet!

    <script src="" type="text/javascript"></script>
    <script type="text/javascript">
            $(document).ready(function () {
                $('a').each(function () {
                    if ($(this).attr('href') == "" || $(this).attr('href') == "#") {

    Open in new window

    Place the above code at the end of the page!

    Hope it helps u...

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now