0

Blank Dropdown with SkipLink in Dynamic Menu

The following is the code to create a dynamic menu binding with the sitemap:

<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"  SiteMapProvider="ExampleSiteMap"/>
<asp:Menu ID="mainMenu" runat="server" Orientation="Horizontal"
DataSourceID="SiteMapDataSource1"
MaximumDynamicDisplayLevels="3">
</asp:Menu>
      <DynamicMenuStyle CssClass="dynamicMenu">  </DynamicMenuStyle>
     <DynamicMenuItemStyle CssClass="dynamicMenuItem"></DynamicMenuItemStyle>

During the testing of the code, there is a blank space before the menu and when the mouse hover over the blank space, there is a URL (http://127.0.0.1:8081/#ctl00_mainMenu_SkipLink) shows on the browser’s status bar:

After some googling work, I just realised it’s seems this usually happens in IE browser:

However, as for my case, it happens in both Firefox and Chrome browser. In order to fix the problem, I just need to add the SkipLinkText=”” in the code and the blank space is no longer exists on the menu:

<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" SiteMapProvider="ExampleSiteMap"/>
<asp:Menu ID="mainMenu" runat="server" Orientation="Horizontal"
DataSourceID="SiteMapDataSource1" SkipLinkText=""
MaximumDynamicDisplayLevels="3">
0

Only one element is allowed at the document top level

This error occurs if you have more than one siteMapNode element under the root element. This error can be reproduced if you have the following configurations in the web.sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="~/" title="Home"  description="Home Page" />
    	<siteMapNode url="~/Example/Site1.aspx" title="Site 1"  description="Site 1" >
        	<siteMapNode url="~/Example/Site2.aspx" title="Site 2"  description="Site 2" />
        	<siteMapNode url="~/Example/Site3.aspx" title="Site 3" description="Site 3" />
     </siteMapNode>
</siteMap>

In order to fix the problem, you need to add the closing tag for the Home Page at the end of the file:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="~/" title="Home"  description="Home Page">
    	<siteMapNode url="~/Example/Site1.aspx" title="Site 1"  description="Site 1" >
        	<siteMapNode url="~/Example/Site2.aspx" title="Site 2"  description="Site 2" />
        	<siteMapNode url="~/Example/Site3.aspx" title="Site 3" description="Site 3" />
     </siteMapNode>
     </siteMapNode>
</siteMap>
0

How to Create Site Maps in ASP.NET

Site Maps is to define the desired page hierarchy or to manage the page navigation of your ASP.NET websites.

Part I (web.sitemap)

  1. In Visual Web Developer Express 2008, you can add a new item with the Site Map template via Solutions Explorer. In MonoDevelop, you can create an empty XML file and give it a name as web.sitemap.
  2. In the web.sitemap, the structure of the page hierarchy can be defined as following:-
    <?xml version="1.0" encoding="utf-8" ?>
    <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
        <siteMapNode url="~/" title="Home"  description="Home Page">
    
        <siteMapNode url="~/Example/Main1.aspx" title="Main 1"  description="Main 1" >
            <siteMapNode url="~/Example/Sub1Main1" title="Sub 1.1"  description="Sub 1.1" />
            <siteMapNode url="~/Example/Sub2Main1.aspx" title="Sub 1.2" description="Sub 1.2" />
            <siteMapNode url="~/Example/Sub3Main1.aspx" title="Sub 1.3" description="Sub 1.3" />
         </siteMapNode>
    
         <siteMapNode url="~/Example/Main2.aspx" title="Main 2" description="Main 2" />
    
         <siteMapNode url="~/Example/Main3.aspx" title="Main 3" description="Main 3" />
    
         <siteMapNode url="~/Example/Main4.aspx" title="Main 4" description="Main 4" />
    
         <siteMapNode url="~/Example/Main5.aspx" title="Main 5" description="Main 5">
         	<siteMapNode url="~/Example/Sub1Main5.aspx" title="Sub 5.1" description="Sub 5.1" />
         	<siteMapNode url="~/Example/Sub2Main5.aspx" title="Sub 5.2" description="Sub 5.2" />
         	<siteMapNode url="~/Example/Sub3Main5.aspx" title="Sub 5.3" description="Sub 5.3" />
         	<siteMapNode url="~/Example/Sub4Main5.aspx" title="Sub 5.4" description="Sub 5.4" />
         </siteMapNode>
         </siteMapNode>
    </siteMap>

Additional Notes

  • The project name is called Example. Each siteMapNode url specification is started with the tilde (~) which means to refer the resources within the website.
  • The <siteMapNode> for parent node only has closing tag if there are child nodes exist and must be defined within the parent node’s <siteMapNode> tag:
     <siteMapNode url="~/Example/Main1.aspx" title="Main 1"  description="Main 1" >
            <siteMapNode url="~/Example/Sub1Main1" title="Sub 1.1"  description="Sub 1.1" />
            <siteMapNode url="~/Example/Sub2Main1.aspx" title="Sub 1.2" description="Sub 1.2" />
            <siteMapNode url="~/Example/Sub3Main1.aspx" title="Sub 1.3" description="Sub 1.3" />
     </siteMapNode>
  • If there is no child node, the tag must be closed at the end of the line:
    <siteMapNode url="~/Example/Main2.aspx" title="Main 2" description="Main 2" />

Part II (web.config)

1. In the web.config, you need to add references to the site map

<configuration>
<system.web>
…
…
 <siteMap defaultProvider="ExampleSiteMap" enabled="true">
    <providers>
    <add name="ExampleSiteMap" type="System.Web.XmlSiteMapProvider"
    siteMapFile="web.sitemap" />
    </providers>
    </siteMap>
</system.web>
</configuration>

Additional Notes:

  • The defaultProvider‘s name (ExampleSiteMap) must have the same name as the name you had given for the sitemap file.
  • If you set the name for defaultProvider with “XmlSiteMapProvider”:
    <siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
  • You will encounter the following error:
    System.Configuration.ConfigurationErrorsException: The default sitemap provider 'XmlSiteMapProvider'does not exist in the provider collection.

Part III (default.aspx)

  1. Bind the SiteMapDataSource and also the TreeView
    <html>
    <head runat="server">
    	<title>Default</title>
    </head>
    <body>
    	<form id="form1" runat="server">
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"  SiteMapProvider="ExampleSiteMap"/>
    <asp:TreeView ID="TreeView1" ExpandDepth="2" DataSourceID="SiteMapDataSource1"
                      runat="server" ImageSet="Events" ShowLines="True">
                     <ParentNodeStyle Font-Bold="False" />
                     <HoverNodeStyle Font-Underline="False" ForeColor="Red" />
                     <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px"
                         VerticalPadding="0px" />
                     <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black"
                         HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
                  </asp:TreeView>
    	</form>
    </body>
    </html>

Additional Notes

  • The TreeView DataSourceID must have the same name with the SiteMapDataSource ID.
  • The SiteMapProvider must have the same name with the name that you had given for the sitemap file in the web.config
  • ExpandDepth is the setting of depth level for the tree view.
  • ImageSet is to set the icon displays for the tree node. The “Events” for ImageSet will result as:SiteMap TreeView
  • HoverNodeStyle is to define the style when the mouse hover over the node. For example, the wording of the item will change to red when the mouse hover over the node.
2

Error “Address already in use” in MonoDevelop

When I tried to run or debug the ASP.NET project in MonoDevelop, the following stacktrace occurs:

Adding applications '/:.'...
Registering application:
Host:          any
Port:          any
Virtual path:  /
Physical path: /home/yee/Desktop/test/test/xsp2

Listening on address: 127.0.0.1

Root directory: /home/yee/Desktop/test/test
Error: System.Net.Sockets.SocketException: Address already in use
at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00000] in &lt;filename unknown&gt;:0
at Mono.WebServer.XSPWebSource.CreateSocket () [0x00000] in &lt;filename unknown&gt;:0
at Mono.WebServer.ApplicationServer.Start (Boolean bgThread) [0x00000] in &lt;filename unknown&gt;:0
at Mono.WebServer.ApplicationServer.Start (Boolean bgThread, System.Exception initialException) [0x00000] in &lt;filename unknown&gt;:0
at (wrapper remoting-invoke-with-check) Mono.WebServer.ApplicationServer:Start (bool,System.Exception)
at Mono.WebServer.XSP.Server.RealMain (System.String[] args, Boolean root, IApplicationHost ext_apphost, Boolean quiet) [0x00000] in &lt;filename unknown&gt;:0

Solution

The MonoDevelop version that I’m using is 2.4. There is a possibility that the location of the commands will be different. The error can be resolved by changing the port number with the following steps:-

  1. Access to the Project > <project name> options
  2. Click the Run dropdown > XSP Web Server
  3. On the General Options, the default port number is 8080. You need to change the port number to other available port numbers, e.g. 8081.

Once the port number has been changed, MonoDevelop can run and debug the project successfully.

1

ASP.NET (with VBNet) Applications on Ubuntu 10.10

MonoDevelop (http://monodevelop.com/) is one of the highly recommended IDE for Ubuntu users to develop and run ASP.NET applications on Ubuntu platform. In order to install MonoDevelop on Ubuntu, you can execute the following command:

sudo apt-get install monodevelop

I created a new solution, an ASP.NET project with VB.NET. I tried to debug and run the project but it was failed with the following error message:

Error: Visual Basic .NET compiler not found (Mono 2.6.7)

In order to resolve the error, you need to download the Mono Visual Basic Compiler (VB.NET) for Ubuntu. The package can be downloaded from here (Ubuntu 10.10 Maverick Meerkat):
https://launchpad.net/ubuntu/maverick/+package/mono-vbnc

Once the package has been downloaded, you can run the ASP.NET application without any errors.