+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / radMenu OnClick Event not working?

radMenu OnClick Event not working?

5 posts, 0 answered
  1. mexner
    mexner avatar
    98 posts
    Registered:
    06 Apr 2006
    20 Jun 2007
    Link to this post
    Hello, great job on sitefinity thus far, I know you all have been very busy.  So I'll keep this short :)

    I am trying to show the "path" in my RadMenu per this article:
    RadMenu - show path

    I have added the code above so that my master.cs file looks like this

    1using System; 
    2using System.Data; 
    3using System.Configuration; 
    4using System.Collections; 
    5using System.Web; 
    6using System.Web.Security; 
    7using System.Web.UI; 
    8using System.Web.UI.WebControls; 
    9using System.Web.UI.WebControls.WebParts; 
    10using System.Web.UI.HtmlControls; 
    11using Telerik.WebControls; 
    12using Telerik.RadMenuUtils; 
    13 
    14public partial class App_Master_Clients : System.Web.UI.MasterPage 
    15
    16    /// <summary> 
    17    /// Summary description for DefaultCS. 
    18    /// </summary> 
    19 
    20    private void Page_Load(object sender, EventArgs e) 
    21    { 
    22        Trace.Write("Page_Load!!!!!!!!!!!!!"); 
    23    } 
    24    protected void RadMenu1_OnItemClick(object sender, RadMenuEventArgs e) 
    25    { 
    26        Trace.Write("Yahoo!!!!!!!!!!!!!!"); 
    27    } 
    28

    My .master page looks like this:
    1<asp:SiteMapDataSource ID="SiteMapDataSource1" ShowStartingNode="false" runat="server" /> 
    2<div id="navcontainer"
    3      <ul id="navlist"
    4        <radM:RadMenu  
    5            ID="RadMenu1" 
    6            DataSourceID="SiteMapDataSource1"  
    7            Skin="timwackel"  
    8            Flow="Horizontal"  
    9            runat="server" 
    10            OnItemClick="RadMenu1_OnItemClick" 
    11             > 
    12             <DefaultGroupSettings OffsetX="10" Flow="vertical" ExpandDirection="Down" /> 
    13        </radM:RadMenu> 
    14     </ul> 
    15    </div> 


    My problem is that the "RadMenu1_OnItemClick" never appears to fire?  When the page loads, i would think the event would NOT fire.  However, when I click on the RadMenu (top level node ), and am taken to a new page, the Trace Output logs never show my Trace stmt....

    What am i doing wrong? 

    Maybe there is a simpler way to highlight the RadMenu item/node that I am under?

    Another example is on your www.sitefinity.com site, as I type this new thread, your navigation bar at the top has the "support" link underlined...that looks great and is what I am trying to accomplish.

    thanks in advance!
  2. mexner
    mexner avatar
    98 posts
    Registered:
    06 Apr 2006
    20 Jun 2007
    Link to this post
    Just to elaborate,
    I'm using SiteFinity v3.0, SQL Server 2005, and C# as my prog lang.

    AND, I forgot to paste my code back in the "itemClick" event....I was frustrated so I started with basic debugging...just testing the event with a Trace stmt.

    here is the code I have in the RadMenu1_ItemClick()
    (It's taken from the telerik "Show Path" Demo...

    1foreach (RadMenuItem childItem in e.Item.Menu.GetAllItems()) 
    2        { 
    3            childItem.CssClass = ""
    4        } 
    5 
    6        e.Item.CssClass = "focused"
    7 
    8        RadMenuItem item = e.Item; 
    9        for (int i = 0; i < e.Item.Level; i++) 
    10        { 
    11            item = (RadMenuItem)item.Parent; 
    12            e.Item.Menu.FindItemByText(item.Text).CssClass = "current"
    13        } 



  3. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    21 Jun 2007
    Link to this post
    Hello Chris,

    Thanks for the nice words.

    The behavior you are describing seems to be normal as when you are binding RadMenu to a SitemapDataSource control it does not postback anymore but rather redirects you to the corresponding page and thus, the OnClick event never occurs. Note that when you point the mouse to any item, it does not show in the status bar javascript function but URL path instead. Perhaps a better approach would be to check the menu items on a page load or when databinding against the current URL.

    Here is one way to do it:
        protected void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e)  
        {  
            if (e.Item.NavigateUrl == SiteMap.CurrentNode.Url)  
            {  
                // here you can set the style for the current item  
                e.Item.ForeColor = Color.Blue;  
            }  
            CmsSiteMapNode node = SiteMap.CurrentNode as CmsSiteMapNode;  
            if (node != null && node.ParentNode != null)  
            {  
                while (node.ParentNode != SiteMap.RootNode)  
                {  
                    node = node.ParentNode as CmsSiteMapNode;  
                }  
                RadMenuItem item = this.RadMenu1.FindItemByUrl(this.ResolveUrl(node.Url));  
                if (item != null)  
                {  
                    // here you can set the style for the top-level item  
                    item.ForeColor = Color.Red;  
                }  
            }  
        } 


    Hope this clarifies the situation. Let me know if I am missing something.

    Best wishes,
    Slavo
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  4. mexner
    mexner avatar
    98 posts
    Registered:
    06 Apr 2006
    21 Jun 2007
    Link to this post
    Slavo,

    Worked like a charm!  Thank you.  FYI, I had to put the OnItemDataBound code into a try catch stmt...whenever I was in SF and attempted to edit the template, it gave me an error,

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 25:     protected void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e)
    Line 26: {
    Line 27: if (e.Item.NavigateUrl == SiteMap.CurrentNode.Url)
    Line 28: {
    Line 29: // here you can set the style for the current item


    Thanks for your help!
  5. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    21 Jun 2007
    Link to this post
    Hi CHRIS mechsner,

    Thank you for bringing this up. You do not have to include the whole thing in a try-catch block. Instead, it is better to add a check for null in the if statement. This is because when you are in a template, it is normal for the SiteMap.CurrentNode to be null, since you are in no specific page of your site.
    The new code should look like this:

            if (SiteMap.CurrentNode != null && e.Item.NavigateUrl == SiteMap.CurrentNode.Url)  
            {  
                // set the style for the current item  
                e.Item.ForeColor = Color.Blue;  
            } 


    Sincerely yours,
    Slavo
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
5 posts, 0 answered