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

Last post 06-09-2009 8:14 PM by pfontyn. 19 replies.

Sort Posts:

  • Re: When MenuItem.NavigateUrl is not set the MenuItemClick event isn't fired!

    04-27-2007, 12:06 PM
    • Member
      6 point Member
    • askforprem
    • Member since 04-27-2007, 2:51 PM
    • Posts 3

    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 

     

  • Re: When MenuItem.NavigateUrl is not set the MenuItemClick event isn't fired!

    05-22-2007, 6:19 PM
    • Member
      2 point Member
    • sun123
    • Member since 05-22-2007, 7:39 PM
    • Posts 3

    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???????????

     

  • Re: When MenuItem.NavigateUrl is not set the MenuItemClick event isn't fired!

    06-12-2007, 10:20 AM
    • Member
      4 point Member
    • gsoftie
    • Member since 06-12-2007, 2:12 PM
    • Posts 2

    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.

     

  • Re: When MenuItem.NavigateUrl is not set the MenuItemClick event isn't fired!

    11-16-2008, 5:48 PM

    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>

  • Re: When MenuItem.NavigateUrl is not set the MenuItemClick event isn't fired!

    06-09-2009, 8:14 PM
    • Member
      8 point Member
    • pfontyn
    • Member since 05-06-2009, 9:46 PM
    • Posts 5

    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!

Page 2 of 2 (20 items) < Previous 1 2