locked
When MenuItem.NavigateUrl is not set the MenuItemClick event isn't fired! RRS feed

  • Question

  • User-1790581902 posted
    First of all... I must say "Very good Job guys!!!", this Adapters are great!
    In the standard Menu control (without the CSS Friendly Adapter) when we setup menu items without setting the NavigateUrl property, the normal behavior is that at runtime clicking on menu item will fire the MenuItemClick server event.

    Using the new CSSFriendly adapter, and leaving null the NavigateUrl property of the menu items, no server event is raised!

    IMO this is an incoherent behavior.... do you agree?
    Hot to fix this?

    Thks.

    Monday, May 1, 2006 4:40 PM

All replies

  • User-1790581902 posted
    Ok, I've figured on my own hacking the MenuAdapter class, I tried as follow:
            private void BuildItems(MenuItemCollection items, bool isRoot, HtmlTextWriter writer)
            {
                if (items.Count > 0)
                {
                    writer.WriteLine();

                    writer.WriteBeginTag("ul");
                    if (isRoot)
                    {
                        writer.WriteAttribute("class", "AspNet-Menu");
                    }
                    writer.Write(HtmlTextWriter.TagRightChar);
                    writer.Indent++;
                                  
                    foreach (MenuItem item in items)
                    {
                        BuildItem(item, writer);
                    }

                    writer.Indent--;
                    writer.WriteLine();
                    writer.WriteEndTag("ul");
                }
            }

            private void BuildItem(MenuItem item, HtmlTextWriter writer)
            {
                Menu menu = Control as Menu;
                if ((menu != null) && (item != null) && (writer != null))
                {
                    writer.WriteLine();
                    writer.WriteBeginTag("li");
                    writer.WriteAttribute("class", item.ChildItems.Count > 0 ? "AspNet-Menu-WithChildren" : "AspNet-Menu-Leaf");
                    writer.Write(HtmlTextWriter.TagRightChar);
                    writer.Indent++;
                    writer.WriteLine();

                    if (item.NavigateUrl.Length > 0)
                    {
                        writer.WriteBeginTag("a");
                        writer.WriteAttribute("href", Page.ResolveUrl(item.NavigateUrl));
                        writer.WriteAttribute("class", "AspNet-Menu-Link");
                        if (item.Target.Length > 0)
                        {
                            writer.WriteAttribute("target", item.Target);
                        }
                        if (item.ToolTip.Length > 0)
                        {
                            writer.WriteAttribute("title", item.ToolTip);
                        }
                        else if (menu.ToolTip.Length > 0)
                        {
                            writer.WriteAttribute("title", menu.ToolTip);
                        }
                        writer.Write(HtmlTextWriter.TagRightChar);
                        writer.Indent++;
                        writer.WriteLine();
                    }
                    else
                    {
                       if (item.Selectable)
                       {
                          writer.WriteBeginTag("a");
                          PostBackOptions options = new PostBackOptions(menu);
                          options.ActionUrl = HttpContext.Current.Request.Url.ToString();
                          options.Argument = item.ValuePath;
                          options.AutoPostBack = false;
                          options.RequiresJavaScriptProtocol = true;
                          options.PerformValidation = true;

                          writer.WriteAttribute("href", Page.ClientScript.GetPostBackEventReference(options));

                          writer.WriteAttribute("class", "AspNet-Menu-Link");
                          if (item.Target.Length > 0)
                          {
                             writer.WriteAttribute("target", item.Target);
                          }
                          if (item.ToolTip.Length > 0)
                          {
                             writer.WriteAttribute("title", item.ToolTip);
                          }
                          else if (menu.ToolTip.Length > 0)
                          {
                             writer.WriteAttribute("title", menu.ToolTip);
                          }
                          writer.Write(HtmlTextWriter.TagRightChar);
                          writer.Indent++;
                          writer.WriteLine();
                       }
                       else
                       {
                          writer.WriteBeginTag("span");
                          writer.WriteAttribute("class", "AspNet-Menu-NonLink");
                          writer.Write(HtmlTextWriter.TagRightChar);
                          writer.Indent++;
                          writer.WriteLine();
                       }
                    }

                    if (item.ImageUrl.Length > 0)
                    {
                        writer.WriteBeginTag("img");
                        writer.WriteAttribute("src", Page.ResolveUrl(item.ImageUrl));
                        writer.WriteAttribute("alt", item.ToolTip.Length > 0 ? item.ToolTip : (menu.ToolTip.Length > 0 ? menu.ToolTip : item.Text));
                        writer.Write(HtmlTextWriter.SelfClosingTagEnd);
                    }

                    writer.Write(item.Text);

                    if (item.NavigateUrl.Length > 0)
                    {
                        writer.Indent--;
                        writer.WriteLine();
                        writer.WriteEndTag("a");
                    }
                    else
                    {
                        writer.Indent--;
                        writer.WriteLine();
                        writer.WriteEndTag("span");
                    }

                    if ((item.ChildItems != null) && (item.ChildItems.Count > 0))
                    {
                        BuildItems(item.ChildItems, false, writer);
                    }

                    writer.Indent--;
                    writer.WriteLine();
                    writer.WriteEndTag("li");
                }

    Now, apart a little problem with css, the menu items will do a postpack, but I can't hadle it in the MenuItemClick event, seems it ins't fired correctly...

    Please, anyone can tell me the correct way to proceed?
    Thks
    Wednesday, May 3, 2006 5:41 AM
  • User-1512748209 posted

    You have a couple of problems. The primary one is that the controladapter receives the postback now, not the menu control. By default it will try and find the correct menu item and raise the onclick event. However, it expects the path to the menu item to be seperated by "\" rather than the pathseperator (normally "/"). In addition, it expects the item name to be prepended with the letter "b". Both of these are undocumented. So, what I did was use the following

    writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(menu, "b" +  item.ValuePath.Replace(menu.PathSeparator, "\"c), True));

    Finally, at the end of the method you need to change

    if (item.NavigateUrl.Length > 0)

    to

    if (item.NavigateUrl.Length > 0 || item.Selectable)

    Tuesday, May 9, 2006 11:16 AM
  • User-597167928 posted

    Hi

     

    Have been trying to get this to work with a pretty simple menu but can't seem to get the syntax right from your post.  Is there a typo in there?

     

    the "/"c seems to cause the issue.

     

    Simon

    Great work by the way!

    Wednesday, May 24, 2006 11:13 AM
  • User-534056067 posted

    I've been looking at this, too.  Here's the code that I ended up putting into my evolving (not yet released) new version of the MenuAdapter (for C#):

     

                        if ((item.NavigateUrl.Length > 0) || item.Selectable)
                        {
                            writer.WriteBeginTag("a");
                            if (item.NavigateUrl.Length > 0)
                            {
                                writer.WriteAttribute("href", Page.Server.HtmlEncode(Page.ResolveUrl(item.NavigateUrl)));
                            }
                            else
                            {
                                writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(menu, "b" +  item.ValuePath.Replace(menu.PathSeparator.ToString(), "\\"), true));
                            }
                            writer.WriteAttribute("class", "AspNet-Menu-Link");
    

    You'll also want to change the "if" that closes the "a" tag so it includes both the check for the NavigateUrl length and item.Selectable like this:

                        if ((item.NavigateUrl.Length > 0) || item.Selectable)
                        {
                            writer.Indent--;
                            writer.WriteLine();
                            writer.WriteEndTag("a");
                        }
                        else
                        {
                            writer.Indent--;
                            writer.WriteLine();
                            writer.WriteEndTag("span");
                        }
    
    Wednesday, May 24, 2006 12:57 PM
  • User-597167928 posted
    Awesome, that's really helpful, will give some feedback on how it goes with our project soon!
    Wednesday, May 24, 2006 1:56 PM
  • User-534056067 posted

    By the way, here is a test page you can use once your enhanced your MenuAdapter:

     

    <%@ Page Language="C#" StylesheetTheme="Basic" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
      void NavigationMenu_MenuItemClick(Object sender, MenuEventArgs e)
      {
        // Display the text of the menu item selected by the user.
        Message.Text = "You selected " + 
          e.Item.Text + ".";
      }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <!--[if lt IE 9]>
        <link runat="server" rel="stylesheet" href="~/BrowserSpecificCSS/IEMenu.css" type="text/css" id="IEMenuCSS" />
    <![endif]--> 
    </head>
    <body>
        <form id="form1" runat="server">
        <div id="SampleMenu">
          <asp:menu id="NavigationMenu" onmenuitemclick="NavigationMenu_MenuItemClick" runat="server" SkinID="SampleMenuVertical" CssSelectorClass="PrettyMenu">      
            <items>
              <asp:menuitem text="Home">
                <asp:menuitem text="Music">
                  <asp:menuitem text="Classical" />
                  <asp:menuitem text="Rock" />
                  <asp:menuitem text="Jazz" />
                </asp:menuitem>
                <asp:menuitem text="Movies" Selectable="false">
                  <asp:menuitem text="Action" />
                  <asp:menuitem text="Drama" />
                  <asp:menuitem text="Musical" />
                </asp:menuitem>
              </asp:menuitem>
            </items>
          </asp:menu>    
        </div>
        
        <asp:label id="Message" runat="server"/>
        
        </form>
    </body>
    </html>
    
    

    Put this page in a site created from the CSS Adapter web template (in VWD) and run it.  When you hit the selectable nodes in the menu you should see the page postback and report what you clicked on.

    Wednesday, May 24, 2006 2:07 PM
  • User-452883518 posted

    When I changed the adapter code and check the demo code all worked fine.

    But whem implementing the same adapter on my own code, no postback.

    The page for the implementation has two menues, one with NavigationUrl and one without. The one without is using values on each node. So without the adapter the postback argument is the value.

    When the changed adapter code didn´t work, I tried to change the postback with the argument of item.value instead of b+ ..... :)

    So the postback url seems exaktly like it was before using the adapter, but no luck.

    I don´t fullt get the b prefix thing. Has this code change since this post ?

     

    Tuesday, June 27, 2006 10:31 AM
  • User-534056067 posted

    Can you post a test page that demonstrates your situation?

    Tuesday, June 27, 2006 11:20 AM
  • User-2028991012 posted

    Hello, I'm having quite the same problem...

    I got a menu which use of course the adapter, and use a sitemapdatasource,

    I would like a second Menu control to display elements of the same level of the one clicked on the first menu. If I am not clear have a look at http://www.eurosport.com/

     I found a note from Micorsoft about that : http://msdn.microsoft.com/en-us/library/16yk5dby.aspx but there example suppose the application to raise the MenuItemClick event... easy for them as they don't set url properties for their siteMapNode.

    NB: the MenuItemClick event is raised when no navigateUrl is set !

    So I tried to override the MenuItem class to add my own attribute but unfortunately this class is sealed and can't be inherited. http://forums.asp.net/thread/1087572.aspx

    I tried to hook this by setting navigateUrl to an empty string programaticaly according to : http://www.codecomments.com/archive320-2006-1-780129.html

    and passing the url by the tooltip as I couldn't find any other property

    protected void MyMenu_MenuItemDataBound(object sender, MenuEventArgs e){

    e.Item.ToolTip = e.Item.NavigateUrl;

    e.Item.NavigateUrl = null;// I also tried e.Item.NavigateUrl = ""}

    And in the adapter after putting in comment the line : //writer.WriteAttribute("href",

    I add the onclick attribute

    writer.WriteAttribute("OnClick", Page.ClientScript.GetPostBackEventReference(this.Control, item.ToolTip, true));

    There is the generated code is :

    <li class="AspNet-Menu-Leaf">
          <a class="AspNet-Menu-Link" OnClick="__doPostBack('MyMenu','/folder/myPage.aspx?culture=fr-FR')" >
           Ma Page
          </a>
    </li>

    When I click on the menuItem the postback occurs but I still don't pass in the menuItemClick event and I really don't know if i can handle the postback by myself ?

    Please tell me if I was clear and specially if I wasn't ;-)

    Monday, July 10, 2006 9:23 AM
  • User-534056067 posted

    Shakhan, did you modify the MenuAdapter class from the original kit so it has the logic I described in the earlier response in this thread?  I'm talking about the reply above that starts with the text:

    I've been looking at this, too.  Here's the code...

    This really should work for you.  Try making this modification and test your change with the text page that I provided above in this thread.  Make sure that works as expected.  If that is OK then try it in your real situation. Does that work, too?

    Monday, July 10, 2006 2:20 PM
  • User-2028991012 posted

    Hi Russ! Thanks for your interest to my problem

    Yes I tried the code you mentionned, but when running a javascript error occurs telling that the function __DoPostBack was undefined.

    I decide to try it again with the test page, and I didn't even need the test page, it's works perfectly, I now pass in the menuItemClick event !!

    Thank you so much Russ for giving me back my faith in .Net ;-) 

    Tuesday, July 11, 2006 4:08 AM
  • User945510275 posted

    It is not that elegant solution maybe but you can also do it this way, 

    --MasterPage  

    Create a property to make MenuItems selected

    Public WriteOnly  Property MenuItemNum() As Integer

    Set(ByVal value As Integer)

    Navigation.Items(value).Selected = True

    End Set

    End Property

     

    Assign  NavigateUrl for each MenuItem  

    <asp:Menu runat="server" ID="Navigation"  ------

    ...

    <asp:MenuItem Text="Report" Value="Report" NavigateUrl="~/Default3.aspx"></asp:MenuItem>

     

     Add this on your Content Pages to reach the any property of the MasterPage 

    <%@ MasterType virtualpath="~/MasterPage.master" %>

     on Content Page  , Page Load event 

    Make proper  MenuItem selected ( Master.MenuItemNum = 0.1......) 

     

     

    Monday, January 1, 2007 9:56 PM
  • User-60437968 posted

    Hi all,

      I have been following this thread since i have the exact same problem.Am new to .NET 2.0

    and greatly appreciate any help.

    Here's my situation

    I have a main menu which is horizontal,and am using the CSS Control adapters(menu)

    The Menu picks its items from the Web.Sitemap which is as follows

    <?xml version="1.0" encoding="utf-8" ?>

    <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >

    <siteMapNode url="~/Home.aspx" title="Home" description="Home">

    <siteMapNode title="VDM" url="~/VDM/Default.aspx" description="Basic Reporting Samples">

    </siteMapNode>

    <siteMapNode title="DataDashBoard" url="~/DataDashBoard/Default.aspx" description="Contains DashBoard Info">

    </siteMapNode>

    <siteMapNode title="Logout" url="~/Logout.aspx" description="Logout Page">

    </siteMapNode>

    </siteMapNode>

    </siteMap>

     

    The Menu in the MasterPage.aspx.cs looks like this

     <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal" CssSelectorClass="PrettyMenu" OnMenuItemClick="Menu1_MenuItemClick" Height="28px" Width="518px">

     

     

    </asp:Menu></span>

    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />

     I modifed the MenuAdapter.cs file in the BuildItem() to look like this

    if (IsLink(item))

    {

    //New code from here

     

    //To here

    if ((item.NavigateUrl.Length > 0) || item.Selectable)

    {

    writer.WriteBeginTag("a");

    if (!String.IsNullOrEmpty(item.NavigateUrl))

    {

    writer.WriteAttribute("href", Page.Server.HtmlEncode(Page.ResolveUrl(item.NavigateUrl)));

    //writer.WriteAttribute("href", Page.Server.HtmlEncode(menu.ResolveClientUrl(item.NavigateUrl)));

    }

    }

    else

    {

    writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(menu, "b" + item.ValuePath.Replace(menu.PathSeparator.ToString(), "\\"), true));

    //writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(menu, "b" + item.ValuePath.Replace(menu.PathSeparator.ToString(), "\\"), true));

    }

    writer.WriteAttribute("class", "AspNet-Menu-Link");

    // writer.WriteAttribute("class", GetItemClass(menu, item));

    //WebControlAdapterExtender.WriteTargetAttribute(writer, item.Target);

     And also the end of the method like this

    if ((item.NavigateUrl.Length > 0) || item.Selectable)

    {

    writer.Indent--;

    writer.WriteLine();

    writer.WriteEndTag("a");

    }

    }

    else

    {

    writer.Indent--;

    writer.WriteLine();

    writer.WriteEndTag("span");

    }

     

    Despite these changes i find that OnMenuItem Click does not fire ,and postbacks do not happen

    Hope someone can help.Thanks 

     

    Friday, April 27, 2007 12:06 PM
  • User-60437968 posted

    Hi all,

      I have been following this thread since i have the exact same problem.Am new to .NET 2.0

    and greatly appreciate any help.

    Here's my situation

    I have a main menu which is horizontal,and am using the CSS Control adapters(menu)

    The Menu picks its items from the Web.Sitemap which is as follows

    <?xml version="1.0" encoding="utf-8" ?>

    <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >

    <siteMapNode url="~/Home.aspx" title="Home" description="Home">

    <siteMapNode title="VDM" url="~/VDM/Default.aspx" description="Basic Reporting Samples">

    </siteMapNode>

    <siteMapNode title="DataDashBoard" url="~/DataDashBoard/Default.aspx" description="Contains DashBoard Info">

    </siteMapNode>

    <siteMapNode title="Logout" url="~/Logout.aspx" description="Logout Page">

    </siteMapNode>

    </siteMapNode>

    </siteMap>

     

    The Menu in the MasterPage.aspx.cs looks like this

     <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal" CssSelectorClass="PrettyMenu" OnMenuItemClick="Menu1_MenuItemClick" Height="28px" Width="518px">

     

     

    </asp:Menu></span>

    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />

     I modifed the MenuAdapter.cs file in the BuildItem() to look like this

    if (IsLink(item))

    {

    //New code from here

     

    //To here

    if ((item.NavigateUrl.Length > 0) || item.Selectable)

    {

    writer.WriteBeginTag("a");

    if (!String.IsNullOrEmpty(item.NavigateUrl))

    {

    writer.WriteAttribute("href", Page.Server.HtmlEncode(Page.ResolveUrl(item.NavigateUrl)));

    //writer.WriteAttribute("href", Page.Server.HtmlEncode(menu.ResolveClientUrl(item.NavigateUrl)));

    }

    }

    else

    {

    writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(menu, "b" + item.ValuePath.Replace(menu.PathSeparator.ToString(), "\\"), true));

    //writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(menu, "b" + item.ValuePath.Replace(menu.PathSeparator.ToString(), "\\"), true));

    }

    writer.WriteAttribute("class", "AspNet-Menu-Link");

    // writer.WriteAttribute("class", GetItemClass(menu, item));

    //WebControlAdapterExtender.WriteTargetAttribute(writer, item.Target);

     And also the end of the method like this

    if ((item.NavigateUrl.Length > 0) || item.Selectable)

    {

    writer.Indent--;

    writer.WriteLine();

    writer.WriteEndTag("a");

    }

    }

    else

    {

    writer.Indent--;

    writer.WriteLine();

    writer.WriteEndTag("span");

    }

     

    Despite these changes i find that OnMenuItem Click does not fire ,and postbacks do not happen

    Hope someone can help.Thanks 

     

    Friday, April 27, 2007 12:06 PM
  • User-60437968 posted

    Hi all,

      I have been following this thread since i have the exact same problem.Am new to .NET 2.0

    and greatly appreciate any help.

    Here's my situation

    I have a main menu which is horizontal,and am using the CSS Control adapters(menu)

    The Menu picks its items from the Web.Sitemap which is as follows

    <?xml version="1.0" encoding="utf-8" ?>

    <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >

    <siteMapNode url="~/Home.aspx" title="Home" description="Home">

    <siteMapNode title="VDM" url="~/VDM/Default.aspx" description="Basic Reporting Samples">

    </siteMapNode>

    <siteMapNode title="DataDashBoard" url="~/DataDashBoard/Default.aspx" description="Contains DashBoard Info">

    </siteMapNode>

    <siteMapNode title="Logout" url="~/Logout.aspx" description="Logout Page">

    </siteMapNode>

    </siteMapNode>

    </siteMap>

     

    The Menu in the MasterPage.aspx.cs looks like this

     <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal" CssSelectorClass="PrettyMenu" OnMenuItemClick="Menu1_MenuItemClick" Height="28px" Width="518px">

     

     

    </asp:Menu></span>

    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />

     I modifed the MenuAdapter.cs file in the BuildItem() to look like this

    if (IsLink(item))

    {

    //New code from here

     

    //To here

    if ((item.NavigateUrl.Length > 0) || item.Selectable)

    {

    writer.WriteBeginTag("a");

    if (!String.IsNullOrEmpty(item.NavigateUrl))

    {

    writer.WriteAttribute("href", Page.Server.HtmlEncode(Page.ResolveUrl(item.NavigateUrl)));

    //writer.WriteAttribute("href", Page.Server.HtmlEncode(menu.ResolveClientUrl(item.NavigateUrl)));

    }

    }

    else

    {

    writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(menu, "b" + item.ValuePath.Replace(menu.PathSeparator.ToString(), "\\"), true));

    //writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(menu, "b" + item.ValuePath.Replace(menu.PathSeparator.ToString(), "\\"), true));

    }

    writer.WriteAttribute("class", "AspNet-Menu-Link");

    // writer.WriteAttribute("class", GetItemClass(menu, item));

    //WebControlAdapterExtender.WriteTargetAttribute(writer, item.Target);

     And also the end of the method like this

    if ((item.NavigateUrl.Length > 0) || item.Selectable)

    {

    writer.Indent--;

    writer.WriteLine();

    writer.WriteEndTag("a");

    }

    }

    else

    {

    writer.Indent--;

    writer.WriteLine();

    writer.WriteEndTag("span");

    }

     

    Despite these changes i find that OnMenuItem Click does not fire ,and postbacks do not happen

    Hope someone can help.Thanks 

     

    Friday, April 27, 2007 12:06 PM
  • User1435348064 posted

    Hi, Am also facing the same problem. Did you solve the problem.  For me MenuItemDataBound is gettimg fired but, absolutely no clue why is it happening, Can anybody help???????????

     

    Tuesday, May 22, 2007 6:19 PM
  • User-93874465 posted

    Hi I had also the same problem, Sitemap-Datasource, no OnClick Event. I did 2 things for a workaround.

    1. I have set the URL for all items in the sitemap datasource to "".

    2. I used the OnMenuItemDataBound Event to make the relevant menu items selectable, e.g.

            protected void Menu_OnMenuItemDataBound(Object sender, MenuEventArgs e)
            {
                e.Item.Selectable = true;
            }

    This is probably not very elegant and there may be better solutions out there, but at least, it worked for me.

    Ulf G.

     

    Tuesday, June 12, 2007 10:20 AM
  • User1265453780 posted

    As you say, the Menu control is supposed to post back when the NavigateUrl property is not set (see http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menuitem.navigateurl.aspx). However, when it is bound to the SitemapDataSource, the Selectable property of an item with no NavigateUrl is set to false, and no postback javascript is generated. This is not to do with the adaptor. If you do a simple test with the normal "unadapted" control, it does exactly the same. 

    But, if you bind the MenuItem's Value property to give it a value (see below), it causes all menu items to generate a postback, whether or not they have NavigateUrl set. This means you can pass the Url to the event handler to process and then redirect. I can find no documentation about this anywhere, which looks to me like an oversight.

     

    <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" StaticDisplayLevels="2">

    <DataBindings>
    <asp:MenuItemBinding DataMember="SiteMapNode" ValueField="Title" />
    </DataBindings>

    </asp:Menu>

    Sunday, November 16, 2008 5:48 PM
  • User2008068812 posted

    I've stumbled across this thread and although my problem isn't exactly the same, I'm experiencing behaviour which seems contrary to the comment above.

    I'm using an XML datasource, bound to an asp.net menu control. I'm using the friendly adapters, but as noted above I really don't think that's got anything to do with my problem.

    Although it seems as though every post on the web is telling people who's click event will not fire to use the Value property to store information as opposed to the NavigateURL field, as soon as I put anything in the Value property the item_click event doesn't fire.

     This will cause the click event to fire:

    <asp:Menu ID="mnuProducts"
    runat="server"
    DataSourceID="xmlDSProductsList"
    CssSelectorClass="MyMenu"
    PathSeparator="^"
    MaximumDynamicDisplayLevels="3"
    EnableViewState="False"
    Orientation="Vertical"
    OnMenuItemClick="mnuProducts_MenuItemClick"
    OnDataBound="mnuProducts_DataBound">
    <DataBindings>
       
    <asp:MenuItemBinding DataMember="productNode" TextField="title"/>
       
    <asp:MenuItemBinding DataMember="productNode" TextField="title"/>
       
    <asp:MenuItemBinding DataMember="productNode" TextField="title"/>
    </DataBindings>

    </asp:Menu>

    This will not:

    <asp:Menu ID="mnuProducts"
    runat="server"
    DataSourceID="xmlDSProductsList"
    CssSelectorClass="MyMenu"
    PathSeparator="^"
    MaximumDynamicDisplayLevels="3"
    EnableViewState="False"
    Orientation="Vertical"
    OnMenuItemClick="mnuProducts_MenuItemClick"
    OnDataBound="mnuProducts_DataBound">
    <DataBindings>
       
    <asp:MenuItemBinding DataMember="productNode" TextField="title" ValueField="folderName"/>
       
    <asp:MenuItemBinding DataMember="productNode" TextField="title" ValueField="folderName" />
       
    <asp:MenuItemBinding DataMember="productNode" TextField="title" ValueField="folderName" />
    </DataBindings>

    </asp:Menu>

    Just to throw a bit more fuel on the fire, if I bind the value that I'm trying to use to the ToolTipField, it works - although it's certainly not ideal. (Especially when the client will want me to remove it from the tooltip!)

    Any help with this would be appreciated immensely!

    Tuesday, June 9, 2009 8:14 PM
  • User-1787502848 posted

    Hi All

            I am using menu control with xmldatasource as datasource to it.
            I am using it inside a web user control(ascx).

    What I want is I should be able to find click event of only last chlidnode of the menu(e.g. category->product->variety) so I will be able to click variety only and go to respective page.

    Thanks in advance
    Suneeta.

    Monday, November 1, 2010 12:44 AM