Welcome Guest Search | Active Topics | Sign In | Register

Menu - ServerSideEvents not firing Options
Posted: Thursday, April 23, 2009 11:29:12 AM
Rank: Member
Groups: Member

Joined: 8/8/2007
Posts: 23
My menu will not fire the codebehind event. The menu is in an .ascx page. That shouldn't make a difference should it??! I've looked through the forums and found one person who said he was able to get his ClientSide event to fire, by taking his code out of the .ascx page and putting it on the .aspx page instead. The difference is, his is ClientSide, and mine is ServerSide.

The problem is, I've got several master pages that reference that Control (with the menu) and I really don't want to take it out of the Control page and put it in several locations.

Please help.
The below is a brief summary of my page and codebehind:

Code: HTML/ASPX
<eo:Menu ID="Menu1" runat="server" EnableViewState="false" SaveStateCrossPages="false" RaisesServerEvent="true"
    CollapseDelay="500" ExpandDelay="100" OnItemClick="Menu1_ItemClick"
    ImageBaseDirectory="~/Images/TabularMenu/" TopLevelItemAlign="Right" AutoSelectTarget="Item">
</eo:Menu>


Code: Visual Basic.NET
Protected Sub Menu1_ItemClick(ByVal sender As Object, ByVal e As EO.Web.NavigationItemEventArgs) Handles Menu1.ItemClick
        Dim tst As Object = e.MenuItem
End Sub
eo_support
Posted: Thursday, April 23, 2009 11:36:15 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Check whether you have MenuItem's NavigateUrl set. NavigateUrl and server event do not work together. If the problem continues, try create a blank new page (without master page) and place your user control directly in your page and see if that works. That should tell you whether the problem is inside your .ascx or outside of your .ascx.

Thanks!
Posted: Thursday, April 23, 2009 12:18:15 PM
Rank: Member
Groups: Member

Joined: 8/8/2007
Posts: 23
Here is the full menu. I am not setting NavigateUrl:

Code: HTML/ASPX
<eo:Menu ID="Menu1" runat="server" EnableViewState="true" 
    SaveStateCrossPages="true" RaisesServerEvent="true"
    CollapseDelay="500" ExpandDelay="100" OnItemClick="Menu1_ItemClick"
    ImageBaseDirectory="~/Images/TabularMenu/" TopLevelItemAlign="Right" 
    AutoSelectTarget="Item" ForceSSL="True">
    <LookItems>
        <eo:MenuItem ItemID="_TopLevelItem" NormalStyle-CssClass="Menu" Height="44" Image-Mode="TextBackground"
            LeftIcon-HoverUrl="menu_HoverLeft_BG_Gray.jpg" Image-HoverUrl="menu_HoverMiddle_BG_Gray.jpg"
            RightIcon-HoverUrl="menu_HoverRight_BG_Gray.jpg" LeftIcon-Url="menu_LeftIcon.jpg"
            Image-Url="menu_Middle_BG.jpg" RightIcon-Url="menu_Middle_BG.jpg" Text-HorizontalAlign="Center"
            Width="125" SubMenuIcon="Auto">
            <SubMenu CollapseEffect-Type="GlideTopToBottom" ExpandEffect-Type="GlideTopToBottom"
                Width="131" Style-CssClass="subMenuWrapper" ShadowDepth="0" ShadowColor="#999999"
                OffsetX="1" OffsetY="0">
            </SubMenu>
        </eo:MenuItem>
        <eo:MenuItem ItemID="_Default" Height="23" Width="131" NormalStyle-CssClass="subMenuNormal"
            HoverStyle-CssClass="subMenuHover" SubMenuIcon="RightIcon" RightIcon-Url="rightArrow8.png"
            RightIcon-HoverUrl="rightArrowHover.png">
            <SubMenu CollapseEffect-Type="GlideLeftToRight" Height="23" Width="131" ExpandEffect-Type="GlideLeftToRight"
                OffsetY="0" OffsetX="-5" Style-CssClass="subMenuLvl2Normal" ShadowColor="#999999"
                ShadowDepth="0">
            </SubMenu>
        </eo:MenuItem>
        <eo:MenuItem ItemID="subMenuBottom" NormalStyle-CssClass="subMenuBottomBorder" Text-Html="">
        </eo:MenuItem>
        <eo:MenuItem ItemID="seperator" NormalStyle-CssClass="seperatorExpanded" Image-Mode="TextBackground">
        </eo:MenuItem>
    </LookItems>
    <TopGroup>
        <Bindings>
            <eo:DataBinding DataField="@url" Property="Status" />
            <eo:DataBinding DataField="@Norm_CssClass" Property="NormalStyle_CssClass" />
            <eo:DataBinding DataField="@Hover_CssClass" Property="HoverStyle_CssClass" />
            <eo:DataBinding DataField="@Image_Url" Property="Image_Url" />
            <eo:DataBinding DataField="@Image_HoverUrl" Property="Image_HoverUrl" />
            <eo:DataBinding DataField="@LookID" Property="LookID" />
        </Bindings>
    </TopGroup>
</eo:Menu>
eo_support
Posted: Thursday, April 23, 2009 12:43:03 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Your menu looks fine. Try to call Menu1.DataBind in your Page_Init or Page_Load. The problem is mostly caused by that when the menu tries to fire server event, the menu item has not been created yet. This often occurs when a parent control's EnableViewState is set to false.

If the problem continues, please create a complete test page that demonstrates the problem and we will be happy to take a look.
Posted: Monday, May 11, 2009 5:48:29 PM
Rank: Member
Groups: Member

Joined: 8/8/2007
Posts: 23
Sorry for the late reply. I've been quite busy. Okay, I've tried creating the page outside of user control page, where I was hoping was causing the problem, but to no avail. I'm still not able to hit my serverevent. I've created just a regular single page all by it's lonely self:

Just a little forward, in my codebehind, I'm using caching to load the menu.

Code: HTML/ASPX
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="TestMEnu.aspx.vb" Inherits="Controls_TestMEnu" %>

<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>
<!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></title>
    <link href="../CSS/TabularMenu.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <eo:Menu ID="Menu1" runat="server" EnableViewState="true" SaveStateCrossPages="true"
            RaisesServerEvent="true" CollapseDelay="500" ExpandDelay="100" OnItemClick="Menu1_ItemClick"
            ImageBaseDirectory="~/Images/TabularMenu/" TopLevelItemAlign="Right" AutoSelectTarget="Item"
            ForceSSL="True">
            <LookItems>
                <eo:MenuItem ItemID="_TopLevelItem" NormalStyle-CssClass="Menu" Height="44" Image-Mode="TextBackground"
                    LeftIcon-HoverUrl="menu_HoverLeft_BG_Gray.jpg" Image-HoverUrl="menu_HoverMiddle_BG_Gray.jpg"
                    RightIcon-HoverUrl="menu_HoverRight_BG_Gray.jpg" LeftIcon-Url="menu_LeftIcon.jpg"
                    Image-Url="menu_Middle_BG.jpg" RightIcon-Url="menu_Middle_BG.jpg" Text-HorizontalAlign="Center"
                    Width="125" SubMenuIcon="Auto">
                    <SubMenu CollapseEffect-Type="GlideTopToBottom" ExpandEffect-Type="GlideTopToBottom"
                        Width="131" Style-CssClass="subMenuWrapper" ShadowDepth="0" ShadowColor="#999999"
                        OffsetX="1" OffsetY="0">
                    </SubMenu>
                </eo:MenuItem>
                <eo:MenuItem ItemID="_Default" Height="23" Width="131" NormalStyle-CssClass="subMenuNormal"
                    HoverStyle-CssClass="subMenuHover" SubMenuIcon="RightIcon" RightIcon-Url="rightArrow8.png"
                    RightIcon-HoverUrl="rightArrowHover.png">
                    <SubMenu CollapseEffect-Type="GlideLeftToRight" Height="23" Width="131" ExpandEffect-Type="GlideLeftToRight"
                        OffsetY="0" OffsetX="-5" Style-CssClass="subMenuLvl2Normal" ShadowColor="#999999"
                        ShadowDepth="0">
                    </SubMenu>
                </eo:MenuItem>
                <eo:MenuItem ItemID="subMenuBottom" NormalStyle-CssClass="subMenuBottomBorder" Text-Html="">
                </eo:MenuItem>
                <eo:MenuItem ItemID="seperator" NormalStyle-CssClass="seperatorExpanded" Image-Mode="TextBackground">
                </eo:MenuItem>
            </LookItems>
            <TopGroup>
                <Bindings>
                    <eo:DataBinding DataField="@url" Property="Status" />
                    <eo:DataBinding DataField="@url" Property="NavigateUrl" />
                    <eo:DataBinding DataField="@Norm_CssClass" Property="NormalStyle_CssClass" />
                    <eo:DataBinding DataField="@Hover_CssClass" Property="HoverStyle_CssClass" />
                    <eo:DataBinding DataField="@Image_Url" Property="Image_Url" />
                    <eo:DataBinding DataField="@Image_HoverUrl" Property="Image_HoverUrl" />
                    <eo:DataBinding DataField="@LookID" Property="LookID" />
                </Bindings>
            </TopGroup>
        </eo:Menu>
        <asp:XmlDataSource ID="XmlDataSource1" TransformFile="~/MenuTransformXSLT.xslt" XPath="MenuItems/MenuItem"
            EnableViewState="false" runat="server" EnableCaching="false" CacheDuration="60"
            CacheKeyDependency="TabularMenu" />
    </div>
    </form>
</body>
</html>


And here is the codebehind:
Code: Visual Basic.NET
Partial Class Controls_TestMEnu
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Dim strUserName As String = HttpContext.Current.User.Identity.Name
        Dim strRealRole As String = Join(Roles.GetRolesForUser(strUserName), ",")
        Dim strBusiness As String = Profile.Business

        XmlDataSource1.CacheKeyDependency = "MenuData" & strBusiness & strRealRole

        If IsNothing(Cache(XmlDataSource1.CacheKeyDependency)) Then
            Cache(XmlDataSource1.CacheKeyDependency) = LoadMenu.getMenuData("HeaderTabs", strBusiness, strRealRole, "HeaderTabs")
        End If

        XmlDataSource1.Data = Cache(XmlDataSource1.CacheKeyDependency)
        If Not IsNothing(XmlDataSource1.Data) Then
            Menu1.DataSourceID = XmlDataSource1.ID
        End If
        Menu1.DataBind()
    End Sub

    Protected Sub Menu1_ItemClick(ByVal sender As Object, ByVal e As EO.Web.NavigationItemEventArgs) Handles Menu1.ItemClick
        Dim tst As Object = e.MenuItem
    End Sub
End Class
eo_support
Posted: Monday, May 11, 2009 5:54:21 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

We can see two problems in your code:

1. You have NavigateUrl set. As mentioned in our first reply, you can not use NavigateUrl and server event at the same time. NavigateUrl goes to a different page, server event goes back to the same page. So you will never get both;

2. You do not need to bind the menu every time. Usually the code should be something like this:

Code: Visual Basic.NET
If Page.IsPostBack Then
   ....do data binding stuff.....
End If


Hope this helps.

Thanks
Posted: Tuesday, May 12, 2009 10:49:57 AM
Rank: Member
Groups: Member

Joined: 8/8/2007
Posts: 23
I'll give that a try, thanks for the quick reply guys!
Posted: Tuesday, May 12, 2009 11:03:34 AM
Rank: Member
Groups: Member

Joined: 8/8/2007
Posts: 23
Okay guys, sorry, I should've known about the navigateURL propery, I turned that off at one time, but must've forgot about it.

However, I tried with your suggestions, but still am unable to get the page to call the code behind for the click event. I don't get it. I read in one of the forum posts where someone said they had fixed their problem for calling the click event (although it was in javascript) by taking it out of the custom control page. Which is what I did as well. In any case...


Here is my revised updated page:

Thanks in advance!


Code: HTML/ASPX
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="TestMEnu.aspx.vb" Inherits="Controls_TestMEnu" %>

<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>
<!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></title>
    <link href="../CSS/TabularMenu.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <eo:Menu ID="Menu1" runat="server" EnableViewState="true" SaveStateCrossPages="true"
            RaisesServerEvent="true" CollapseDelay="500" ExpandDelay="100" OnItemClick="Menu1_ItemClick"
            ImageBaseDirectory="~/Images/TabularMenu/" TopLevelItemAlign="Right" AutoSelectTarget="Item"
            ForceSSL="True">
            <LookItems>
                <eo:MenuItem ItemID="_TopLevelItem" NormalStyle-CssClass="Menu" Height="44" Image-Mode="TextBackground"
                    LeftIcon-HoverUrl="menu_HoverLeft_BG_Gray.jpg" Image-HoverUrl="menu_HoverMiddle_BG_Gray.jpg"
                    RightIcon-HoverUrl="menu_HoverRight_BG_Gray.jpg" LeftIcon-Url="menu_LeftIcon.jpg"
                    Image-Url="menu_Middle_BG.jpg" RightIcon-Url="menu_Middle_BG.jpg" Text-HorizontalAlign="Center"
                    Width="125" SubMenuIcon="Auto">
                    <SubMenu CollapseEffect-Type="GlideTopToBottom" ExpandEffect-Type="GlideTopToBottom"
                        Width="131" Style-CssClass="subMenuWrapper" ShadowDepth="0" ShadowColor="#999999"
                        OffsetX="1" OffsetY="0">
                    </SubMenu>
                </eo:MenuItem>
                <eo:MenuItem ItemID="_Default" Height="23" Width="131" NormalStyle-CssClass="subMenuNormal"
                    HoverStyle-CssClass="subMenuHover" SubMenuIcon="RightIcon" RightIcon-Url="rightArrow8.png"
                    RightIcon-HoverUrl="rightArrowHover.png">
                    <SubMenu CollapseEffect-Type="GlideLeftToRight" Height="23" Width="131" ExpandEffect-Type="GlideLeftToRight"
                        OffsetY="0" OffsetX="-5" Style-CssClass="subMenuLvl2Normal" ShadowColor="#999999"
                        ShadowDepth="0">
                    </SubMenu>
                </eo:MenuItem>
                <eo:MenuItem ItemID="subMenuBottom" NormalStyle-CssClass="subMenuBottomBorder" Text-Html="">
                </eo:MenuItem>
                <eo:MenuItem ItemID="seperator" NormalStyle-CssClass="seperatorExpanded" Image-Mode="TextBackground">
                </eo:MenuItem>
            </LookItems>
            <TopGroup>
                <Bindings>
                    <eo:DataBinding DataField="@url" Property="Status" />
                    <eo:DataBinding DataField="@Norm_CssClass" Property="NormalStyle_CssClass" />
                    <eo:DataBinding DataField="@Hover_CssClass" Property="HoverStyle_CssClass" />
                    <eo:DataBinding DataField="@Image_Url" Property="Image_Url" />
                    <eo:DataBinding DataField="@Image_HoverUrl" Property="Image_HoverUrl" />
                    <eo:DataBinding DataField="@LookID" Property="LookID" />
                </Bindings>
            </TopGroup>
        </eo:Menu>
        <asp:XmlDataSource ID="XmlDataSource1" TransformFile="~/MenuTransformXSLT.xslt" XPath="MenuItems/MenuItem"
            EnableViewState="false" runat="server" EnableCaching="false" CacheDuration="60"
            CacheKeyDependency="TabularMenu" />
    </div>
    </form>
</body>
</html>



Code: Visual Basic.NET
Partial Class Controls_TestMEnu
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        If Not Page.IsPostBack Then
            Dim strUserName As String = HttpContext.Current.User.Identity.Name
            Dim strRealRole As String = Join(Roles.GetRolesForUser(strUserName), ",")
            Dim strBusiness As String = Profile.Business

            XmlDataSource1.CacheKeyDependency = "MenuData" & strBusiness & strRealRole

            If IsNothing(Cache(XmlDataSource1.CacheKeyDependency)) Then
                Cache(XmlDataSource1.CacheKeyDependency) = LoadMenu.getMenuData("HeaderTabs", strBusiness, strRealRole, "HeaderTabs")
            End If

            XmlDataSource1.Data = Cache(XmlDataSource1.CacheKeyDependency)
            If Not IsNothing(XmlDataSource1.Data) Then
                Menu1.DataSourceID = XmlDataSource1.ID
            End If
            Menu1.DataBind()
        End If
    End Sub

    Protected Sub Menu1_ItemClick(ByVal sender As Object, ByVal e As EO.Web.NavigationItemEventArgs) Handles Menu1.ItemClick
        Dim tst As Object = e.MenuItem
    End Sub
End Class
eo_support
Posted: Tuesday, May 12, 2009 11:30:21 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Can you post all the related file and also isolate the problem so that the we can run the page here? Your code looks fine to us but we are not able to run it here because we do not have the XML and XSLT files as well as your user and profile environment.

Thanks
Posted: Tuesday, May 12, 2009 3:12:45 PM
Rank: Member
Groups: Member

Joined: 8/8/2007
Posts: 23
For the sake of making this easy on everyone, I've simplified the page as much as possible. I've already transformed the file and am providing the xml that the menu uses. I will post below. However, I believe I've narrowed down the problem. Earlier, it was said that I should not bind to the URL. So I took that binding out. However, my transformed XML has the URL property in it. I've found that whenever the XML has a URL property, that is when I'm not able to get to menu item's click event. Is that by design then? If so, I have some questions below (after my code):

HTML:
Code: HTML/ASPX
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="TestMEnu.aspx.vb" Inherits="Controls_TestMEnu" %>

<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>
<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <eo:Menu ID="Menu1" runat="server" SaveStateCrossPages="True" RaisesServerEvent="True"
            DataSourceID="XmlDataSource1" CollapseDelay="500" ExpandDelay="100" OnItemClick="Menu1_ItemClick"
            ImageBaseDirectory="~/Images/TabularMenu/" TopLevelItemAlign="Right">
        </eo:Menu>
        <asp:XmlDataSource ID="XmlDataSource1" DataFile="~/Controls/MenuTransformed.xml" 
            XPath="MenuItems/MenuItem" runat="server" CacheDuration="60" />
    </div>
    </form>
</body>
</html>


VB Codebehind:
Code: Visual Basic.NET
Partial Class Controls_TestMEnu
    Inherits System.Web.UI.Page

    Protected Sub Menu1_ItemClick(ByVal sender As Object, ByVal e As EO.Web.NavigationItemEventArgs) Handles Menu1.ItemClick
        Page.Title = "It Worked" & e.MenuItem.Text.ToString
    End Sub

End Class


Code: XML

<MenuItems>
  <MenuItem title="MY COMMUNITY" description="Community and Company" url="" Image_Url="" Image_HoverUrl="" Norm_CssClass="" Hover_CssClass="" Menu_Category="" Page="" LookID="">
    <MenuItem title="Home Page" description="Home" url="~/Home.aspx" Image_Url="" Image_HoverUrl="" Norm_CssClass="" Hover_CssClass="" Menu_Category="" Page="" LookID="" />
    <MenuItem title="TestParent" description="" url="~/Controls/TestMenu.aspx" Image_Url="" Image_HoverUrl="" Norm_CssClass="" Hover_CssClass="" Menu_Category="" Page="" LookID="">
      <MenuItem title="TestChild" description="" url="~/Controls/TestMenu.aspx" Image_Url="" Image_HoverUrl="" Norm_CssClass="" Hover_CssClass="" Menu_Category="" Page="" LookID="" />
    </MenuItem>
    <MenuItem title="All American" description="All American Home" url="~/Content.aspx?Page=AllAmerican" Image_Url="" Image_HoverUrl="" Norm_CssClass="" Hover_CssClass="" Menu_Category="" Page="AllAmerican" LookID="" />
    <MenuItem title="" description="" url="" Image_Url="" Image_HoverUrl="" Norm_CssClass="" Hover_CssClass="" Menu_Category="" Page="" LookID="subMenuBottom" />
  </MenuItem>
</MenuItems>

So, if it IS by design that the page will only call the Menu_ItemClick event if there isn't a URL set (which makes sense), then what is the standard by which most everyone calls their other pages? Response.Redirect in the code behind? 

Thanks!
Posted: Tuesday, May 12, 2009 3:13:43 PM
Rank: Member
Groups: Member

Joined: 8/8/2007
Posts: 23
So, if it IS by design that the page will only call the Menu_ItemClick event if there isn't a URL set (which makes sense), then what is the standard by which most everyone calls their other pages? Response.Redirect in the code behind?

Thanks!
eo_support
Posted: Tuesday, May 12, 2009 9:56:49 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

As you have noticed, the menu automatically picks Url from your xml file and set NavigateUrl based on that. This behavior is documented here (under "Mapping data source attribute to item's property" section):

http://doc.essentialobjects.com/library/1/menucommon/databinding/populate_datasource.aspx

You do not "call other page" from your code in this case. Once you set NavigateUrl the menu automatically direct to the target page when user clicks it. That's in fact how most people use the menu --- set the NavigateUrl and be done with it.

Thanks

Posted: Wednesday, May 13, 2009 9:29:28 AM
Rank: Member
Groups: Member

Joined: 8/8/2007
Posts: 23
Yes I understand. However, how would one then be able to call the menuItem.Click event, if setting the NavigateUrl property?
eo_support
Posted: Wednesday, May 13, 2009 9:36:23 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
They can not. You either get ItemClick event or NavigateUrl. You can not get both.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.