Closing ASP menu when moving mouse - asp.net

I'm working with a project that has as ASP menu (), which I can't get to close. All I want it to do is to collapse when the mouse is not hovering it. Is there a setting or something to fix this? Maybe a simple problem but I've searched everywhere with no luck.
I can expand the menu just fine, and when I move to a different node it switches to that just. The problem is when I move the mouse outside the entire menu, it stays open. Shouldn't there be some simple setting for this? Do I really have to jump through several hoops of javascript and events to fix this?

By default, menu should collapse as soon as cursor is out. Strip out all css and test it with simple code.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="MenuTest.aspx.cs" Inherits="WebApplication2012.MenuTest" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Menu runat="server" DataSourceID="MenuDataSource"></asp:Menu>
<asp:SiteMapDataSource ID="MenuDataSource" runat="server" ShowStartingNode="false"
SiteMapProvider="XmlSiteMapProvider" />
</form>
</body>
</html>
// MenuTest.sitemap
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Home" title="Home" description="Home">
<siteMapNode url="Monday" title="One" description="One" >
<siteMapNode url="Monday - One" title="Monday - One" description="Monday - One" />
<siteMapNode url="Monday - Two" title="Monday - Two" description="Monday - Two" />
<siteMapNode url="Monday - Three" title="Monday - Three" description="Monday - Three" />
</siteMapNode>
<siteMapNode url="Tuesday" title="Tuesday" description="Tuesday" />
</siteMapNode>
</siteMap>
// web.config
<system.web>
...
<siteMap defaultProvider="XmlSiteMapProvider">
<providers>
<add name="XmlSiteMapProvider" type="System.Web.XmlSiteMapProvider" siteMapFile="~/MenuTest.sitemap" />
</providers>
</siteMap>
</system.web>

Related

ASP.NET SiteMap Display All Nodes

I have a .sitemap file that contains all of my nodes that I want to display for my side navigation. I am having trouble displaying all of my nodes when I get to the sub level. Everything just disappears when I visit the sub-page. In otherwords, when I am in the homepage.aspx page, all of my nodes are visible. When I enter the level1a.aspx page, all of the nodes disappear. I have no code behind. Is there a setting to display all nodes? Or would I need to write code to display them all?
Here are files:
web.config
<siteMap>
<providers>
<add name="SiteMap" type="System.Web.XmlSiteMapProvider" siteMapFile="~/my.sitemap" />
</providers>
</siteMap>
control.ascx
<asp:SiteMapDataSource ID="SiteMapDataSource1" SiteMapProvider="SiteMap" runat="server" />
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1"></asp:Menu>
my.sitemap
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="/HomePage.aspx" title="Home Page" description="">
<siteMapNode url="/level1.aspx" title="Level 1" description="">
<siteMapNode url="/level1a.aspx" title="Level 1 A" description="" />
<siteMapNode url="/level1b.aspx" title="Level 1 B" description="" />
</siteMapNode>
</siteMapNode>
</siteMap>
I just made the experiment and it works fine...
Double check all your pages contain a reference to your user control
This is what I did
UC
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="MyMenuUC.ascx.cs" Inherits="WebApplication1.MyMenuUC" %>
<asp:SiteMapDataSource runat="server" ID="mySiteMapDataSource" ShowStartingNode="false" />
<asp:Menu runat="server" DataSourceID="mySiteMapDataSource"></asp:Menu>
Web.sitemap
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/Default.aspx" title="Home" description="">
<siteMapNode url="~/MenuWithUC1.aspx" title="page 1" description="" />
<siteMapNode url="~/MenuWithUC2.aspx" title="page 2" description="" />
</siteMapNode>
</siteMap>
MenuWithUC1.aspx
<%# Register Src="~/MyMenuUC.ascx" TagName="SharedMenu" TagPrefix="menu" %>
....
<menu:SharedMenu runat="server" />
<asp:Button ID="Button1" Text="post me" runat="server" />
MenuWithUC2.aspx
<%# Register Src="~/MyMenuUC.ascx" TagName="SharedMenu" TagPrefix="menu" %>
....
<menu:SharedMenu runat="server" />
<asp:Button Text="post me" runat="server" />
The buttons on each page are just to test that the Menu control keeps its state on each post
try with EnableViewState = true
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" EnableViewState="true"></asp:Menu>

using sitemap path with treeview

i have inserted a sitemap data source + treeview control, written up my sitemap file, all the folder/file names are correct, yet, treeview is not reading directly from the sitemap file. Any suggestions?
sitemap code is shown below:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/Default.aspx" title="Home" description="">
<siteMapNode url="~/about2.aspx" title="About" description="" >
</siteMapNode>
<siteMapNode url="~/menu.aspx" title="Menu" description="">
<siteMapNode url="~/starters.aspx" title="Starters" description=""/>
<siteMapNode url="~/mains.aspx" title="Mains" description=""/>
<siteMapNode url="~/desserts.aspx" title="Desserts" description=""/>
<siteMapNode url="~/drinks.aspx" title="Drinks" description=""/>
<siteMapNode url="~/specials.aspx" title="Specials" description=""/>
</siteMapNode>
<siteMapNode url="~/contact.aspx" title="Contact" description="">
</siteMapNode>
<siteMapNode url="~/findus.aspx" title="Find Us" description="">
</siteMapNode>
<siteMapNode url="~/reviews.aspx" title="Reviews" description="">
</siteMapNode>
</siteMapNode>
</siteMap>
could it be that the webforms i want the sitemap to work with are added to the root of the folder, and not in a folder? Help would be greatly appreciated. Thank you.
source code for asp.net/html.
<%# Page Language="VB" AutoEventWireup="false" CodeFile="sitemap.aspx.vb" Inherits="sitemap" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<br />
</div>
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1">
</asp:TreeView>
</form>
</body>
</html
>
Came across this searching for something else. Your SiteMapDataSource has no "SiteMapProvider" specified. How does it know which map to use?
This has to be specified in web.config in the systen.web sections
<siteMap defaultProvider="secure" enabled="true">
<providers>
<add name="mapname" description="my site map" type="System.Web.XmlSiteMapProvider" siteMapFile="filename.sitemap" />
</providers>
</siteMap>
So you should set SiteMapProvider="mapname"

SiteMapPath not showing sitemap as expected

Using a <asp:SiteMapPath> control with the Web.sitemap file below:
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<asp:SiteMapPath ID="SiteMapPath1" runat="server"></asp:SiteMapPath>
<asp:Image ID="Image1" runat="server" ImageUrl="~/closed-sign.jpg" Height="300" Width="400" />
While running it's not showing me way it should show as in this example.
It's only showing the image, with no sitemap.
How can this be fixed?
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.aspx" title="Home" description="Home Page">
<siteMapNode url="StandardToolBox.aspx" title="Standard ToolBox Control" description="Standard ToolBox Control">
<siteMapNode url="BulletedList.aspx" title="BulltedList Example" description="BulltedList Control Simple Example" />
<siteMapNode url="CheckBox.aspx" title="CheckBox Example" description="CheckBox Control Simple Example" />
<siteMapNode url="CheckBoxList.aspx" title="CheckBoxList Example" description="CheckBoxList Control Simple Example" />
<siteMapNode url="Image.aspx" title="Image Control Example" description="Image Control Simple Example"/>
</siteMapNode>
<siteMapNode url="DataToolBox.aspx" title="Data ToolBox Control" description="Data ToolBox Control">
<siteMapNode url="SqlDataSource.aspx" title="SqlDataSource Example" description="SqlDataSource Simple Example" />
<siteMapNode url="XmlDataSource.aspx" title="XmlDataSource Example" description="XmlDataSource Simple Example" />
</siteMapNode>
The code you're using works fine.
Likely the page you're looking at is NOT anywhere in the list on the site map.
Ensure you're running this sample on a page named like:
StandardToolBox.aspx
CheckBox.aspx
DataToolBox.aspx
This is a breadcrumb control. It will only show links back to its parents. It will not send links to siblings.

Show/Hide SiteMap Menu/Repeater on MasterPage

Master Page:
<ul>
<li class="first"><asp:HyperLink runat="server" ID="lnkHome"
NavigateUrl="~/Forms/Default.aspx">Home</asp:HyperLink></li>
<asp:Repeater runat="server" ID="Repeater1" DataSourceID="SiteMapDataSource1"
EnableViewState="False">
<ItemTemplate>
<li>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %>
</asp:HyperLink>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
Web.SiteMap
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode id="SiteHome" url="~/Forms/Default.aspx" title="Home"
description="Default">
<siteMapNode id="SiteAbout" url="~/Forms/Aboutus.aspx" title="About us"
description="About Us"/>
<siteMapNode id="SiteNew" url="~/Forms/New.aspx" title="New"
description="My Sample Page"/>
</siteMapNode>
Design:
HOME | About us | My Sample Page
I am new on ASP.Net Webforms and i am creating my first Project.
I am using Repeater to navigate page urls.
On my Master/Page.cs Code Behind I need to Hide
[My Sample Page] based on my Login Account.
something like:
if(UserGroup="Admin")
{
//Show My Sample Page
HOME | About us | My Sample Page
}
else if(UserGroup="User1")
{
//Hide About Us
HOME | About us
}
else
{
// Show Home Only
HOME
}
How to do it in form Load?
Thanks in Regards..
The correct way to do this is define a site map provider in your Web.Config and make sure you set the attribute securityTrimmingEnabled="true".
<siteMap defaultProvider="MySiteMap">
<providers>
<clear/>
<add
name="MySiteMap"
type="System.Web.XmlSiteMapProvider"
securityTrimmingEnabled="true"
siteMapFile="~/Web.SiteMap" />
</providers>
</siteMap>
In your Forms folder create a Web.Config file and include the following
<?xml version="1.0"?>
<configuration>
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
<location path="New.aspx">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
</configuration>
Now ASP.Net will take care of showing which parts of your site map to which users.
Eg: In this case it will hide your My Sample Page page from un-authenticated users.
Try something like:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Url") %>'
Visible='Eval("Title") = "My Sample Page" ? this.IsAdmin.ToString() : "True"' >
<%# Eval("Title") %>
</asp:HyperLink>

How do I make a sitemap based menu in asp.net with onl top level elements?

I'm trying to make a menu based off of an asp.net sitemap. How do you nest the sitemap nodes so that they all appear on the same level. Here is what I have:
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode>
<siteMapNode url="~/Default.aspx" title="Home" description="link to Home" />
<siteMapNode url="~/about.aspx" title="About" description="abot" />
</siteMapNode>
</siteMap>
Here is what the code for the Menu control looks like:
<asp:Menu ID="Menu1" runat="server" BackColor="#E3EAEB"
DataSourceID="SiteMapDataSource1"
</asp:Menu>
They both appear as 2nd tier elements underneath an arrow. Sorry for the beginner question but I've never used the menu control before.
You just need to set the StaticDisplayLevels and only have one level in the sitemap file.
<asp:Menu runat="server" DataSourceID="SiteMapDataSource" StaticDisplayLevels="2" >
</asp:Menu>
An example of the web.sitemap:
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode>
<siteMapNode url="Default.aspx" title="Home" description="" />
<siteMapNode url="Page2.aspx" title="Page2" description="" />
</siteMapNode>
</siteMap>

Resources