Welcome Guest Search | Active Topics | Sign In | Register

Slider Menu - Populate using code behind Options
puffworld
Posted: Wednesday, January 14, 2009 2:16:30 PM
Rank: Newbie
Groups: Member

Joined: 1/14/2009
Posts: 7
Good Day:

I've been trying to find code examples to populate the Slider menu using code behind and also to be able to set a portion of the menu as expanded using code behind. I have not been able to find any examples on doing this. Does anyone have examples of using vb.net or C# code behind to populate and manipulate the menu in code behind?

Thanks for any help in advance.

Mary
eo_support
Posted: Wednesday, January 14, 2009 2:58:08 PM
Rank: Administration
Groups: Administration

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

You can find all the data binding samples here:

http://www.essentialobjects.com/Demo/Default.aspx?path=Menu\menu_programming\_i0

The sample is for Menu, however data binding for Menu and SlideMenu are exactly the same. The same sample is also available locally on your machine. Also before you go through the code, you will want to go over the documentation:

http://www.essentialobjects.com/ViewDoc.aspx?t=MenuCommon%2fDataBinding%2fDataBinding_overview.html

To set a portion of the menu expanded, you would need to set the corresponding top level item's Selected to true. For example, the following code set the second sliding pane as expanded:

Code: C#
SlideMenu1.Items[1].Selected = true;


Hope this helps.

Thanks
puffworld
Posted: Wednesday, January 14, 2009 4:23:15 PM
Rank: Newbie
Groups: Member

Joined: 1/14/2009
Posts: 7
I see by the code in the demo that i need to use

menu1.Items.Add("Menu Item 1")

How do you add a sub menu item?
eo_support
Posted: Wednesday, January 14, 2009 5:19:29 PM
Rank: Administration
Groups: Administration

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

There are various ways to do it. One way can be:

Code: Visual Basic.NET
menu1.Items.Items(0).SubItems.Add("sub item 1")


If you have any more questions about these, you will want to rely on reference section of the documentation, which contains detailed information for every property/method. For example, for the above question, you would first find menu1.Items:

http://www.essentialobjects.com/ViewDoc.aspx?t=EO.Web.Menu.Items.html

This means you can use the following expression to access all top level menu items:

Code: Visual Basic.NET
menu1.Items


Note the return type for Menu.Items is MenuItemCollection, click the type to follow through and you should see reference for MenuItemCollection, expand "Properties" you would see it has an "Item" property for you to access individual items:

http://www.essentialobjects.com/ViewDoc.aspx?t=EO.Web.MenuItemCollection.Item.html

This means you can use the following experession to access the first top level menu item:

Code: Visual Basic.NET
menu1.Items.Item(0)


Once you have the returned MenuItem object, you go here:

http://www.essentialobjects.com/ViewDoc.aspx?t=EO.Web.MenuItem.html

Expand "Properties" from the left tree view and you would see SubItems property. This means you can use the following expression to get the sub item collection:

Code: Visual Basic.NET
menu1.Items.Item(0).SubItems


Per the reference, the return type for SubItems is also MenuItemCollection:

http://www.essentialobjects.com/ViewDoc.aspx?t=EO.Web.MenuItemCollection.html

Which is the same type as menu1.Items. Expand "Methods" from the left side tree view and you will see all methods avaiable to this object. You should see a number of Add methods, one of them taking a single string parameter. This is why you can have.

Code: Visual Basic.NET
menu1.Items.Item(0).SubItems.Add("menu item")


Note all the documentation is available locally as a .chm help file, which is a lot faster than the online version. So you may want to start from there. Obviously it doesn’t make much sense for us to repeat everything that’s already there at here. So you will want to check that first, it should answer most of your question right away.

Hope this helps.

Thanks!

puffworld
Posted: Thursday, January 15, 2009 7:16:08 AM
Rank: Newbie
Groups: Member

Joined: 1/14/2009
Posts: 7
Good Day:

OK one more question. Say I wanted to add navigation to it in code behind. actually lets say we have the following menu

<eo:SlideMenu runat="server" id="SlideMenu1" SingleExpand="False" ControlSkinID="None" Width="220px">
<TopGroup>
<Items>
<eo:MenuItem Text-Html="Main Menu 1">
<SubMenu>
<Items>
<eo:MenuItem Text-Html="Main 1 Sub 1" NavigateUrl="Main1Sub1.aspx" TargetWindow="_Blank"></eo:MenuItem>
<eo:MenuItem Text-Html="Main 1 Sub 2" NavigateUrl="Main1Sub2.aspx"></eo:MenuItem>
</Items>
</SubMenu>
</eo:MenuItem>
<eo:MenuItem Text-Html="Main Menu 2">
<SubMenu>
<Items>
<eo:MenuItem Text-Html="Main 2 Sub 1" NavigateUrl="Main2Sub1.aspx"></></eo:MenuItem>
<eo:MenuItem Text-Html="Main 2 Sub 2" NavigateUrl="Main2Sub2.aspx"></></eo:MenuItem>
</Items>
</SubMenu>
</eo:MenuItem>
<eo:MenuItem Text-Html="Main Menu 2" NavigationUrl="MainMenu3.aspx"></eo:MenuItem>

</Items>
</TopGroup>

</eo:SlideMenu>

How would I do this in code:
SlideMenu1.Items.Add("MainMenu1")
SlideMenu1.Items.Item(0).SubItems.Add("Main 1 Sub 1")
SlideMenu1.Items.Item(0).SubItems.Add("Main 1 Sub 2")
SlideMenu1.Items.Add("MainMenu2")
SlideMenu1.Items.Item(1).SubItems.Add("Main 2 Sub 1")
SlideMenu1.Items.Item(1).SubItems.Add("Main 2 Sub 2")
SlideMenu1.Items.Add("MainMenu3")

My Questions are:
1. how do I add navigation URL to the subItem?
2. how do I add a style or CssClass to either the sub item or the main item? Say the cssClass Name for the Main Menu Items was MenuMain, and the cssClass for the sub Menu items was MenuSub.
3. if the main item has no sub items how do I add a navigation URL to the Main Menu Item?
4. how do you add a Target for the NavigationUrl?


Thanks for your help.
Mary
eo_support
Posted: Thursday, January 15, 2009 7:47:57 AM
Rank: Administration
Groups: Administration

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

For the first question, you really need to rely on the reference. Everything is already there and we won't be able to afford to support you if you do not know how to or do not want to use the documentation. The basic idea is really very simple: whatever you wanted to do, you do it by finding the corresponding object, then either set a property or call a method on that object. Our previous rely has demonstrated how to do this in great detail, so we would expect you to follow this approach to solve this problem.

For the second question, you will need to understand how our menu is styled first. And that’s much more than a single post can cover. Once again, you will want to go over the documentation under “Using EO.Web Menu -> Navigation Items and Groups”, “Using EO.Web Menu -> Look, Skin and Theme”, “Style and Appearance”.

It is important for you to understand what our support does. We understand that it would be nice if we could simply provide you the correct code every time you need to do something, but then it would be basically us coding for you. And obviously it is not practical for us even if we wanted to do that. We don’t mind to give you a few sample pieces so that you can get an idea how our product works. But in the long run, you will need to be able to rely on the documentation and your own skills.

Thanks!
puffworld
Posted: Thursday, January 15, 2009 10:13:56 AM
Rank: Newbie
Groups: Member

Joined: 1/14/2009
Posts: 7
Good Day:

I did look in the reference and also the samples. None of them show how to do those things I have asked in code behind.

All the examples show how to do it with the html in the object on the page, not in code behind.

Is there an example that shows this anywhere that you can think of? If so a link to that would be helpful.

We are planning on purchasing the entire suite of controls from you if we can get things to work in code behind. All our menus on our sites are dynamically generated and we need to be able to do them from code behind.

All you code examples are done as html code and not in code behind. If you can just point me to an example of generating a slide menu that has the addition of the menu items and submenu items the addition of the navigation url and target window I can handle the styles I've figured out a way to do that.

It's really the navigation url in the code behind that is the issue. And I have not found an example in the documentation that shows how this is done.

Thanks for your help.

Mary.
eo_support
Posted: Thursday, January 15, 2009 10:56:02 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi Mary,

I am not sure why you think all of our samples are only in html. For each of the samples, there is a Demo.ascx, which contains HTML code, and an Demo.cs/Demo.vb, which contains the code behind. So that will be what you are looking for. The easiest way is to open the whole sample project with Visual Studio (go to Start -> All Programs -> EO.Web Controls 2008 -> EO.Web Controls for ASP.NET xxx -> Live Demo Source Code -> xxx) and then browse the samples. You can also go to our installation folder (the default location is c:\Program Files\Essential Objects\EO.Web Controls 2008) to look for those files.

As we have already pointed out in our previous post, for whatever you do, you get the corresponding object first, then call a method or set a property on that object. We don't mind to provide you the following syntax:

Code: Visual Basic.NET
'Get the first top level menu item
'You can get any item, for example, the following code get the
'second child item of the first top level item
'Dim menuItem as EO.Web.MenuItem = menu1.Items.Item(0).SubItems.Item(1)
Dim menuItem as EO.Web.MenuItem = menu1.Items.Item(0)

'Now set the NavigateUrl property on this menu item object
menuItem.NavigateUrl = "somepage.aspx"


The first part of this code "get the object", the second part "set the property". This is basically how every programming question is almost always divided into these two questions first: "How to get the object" and "what property/method can be set/called on that object". That's exactly what you will be looking for in the reference section. You look for what objects/properties/methods are available instead of just code pieces.

Further more, taken the sample code above, you need to be very clear about which item's NavigateUrl you are setting and there are various ways for you to get a menu item object, obviously that depends on your business logics and we can't do that for you. That's also where you need to read the reference section to find out exactly how to get the correct menu item. It is impossible for us to have sample code ready for every scenario that our customer may have. That's why the reference, not just the sample code is so important here.

Hope this helps.

Thanks

puffworld
Posted: Thursday, January 15, 2009 11:04:33 AM
Rank: Newbie
Groups: Member

Joined: 1/14/2009
Posts: 7
I'm looking at the code for the demos for the slider menu, none of them have code behind. However, your example in the previous post is exactly what I needed. It has answered my question.

Thanks for your help.

Mary.
eo_support
Posted: Thursday, January 15, 2009 11:11:23 AM
Rank: Administration
Groups: Administration

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

Glad it helped. The slide menu does not provide any code behind because the code is the same for SlideMenu and Menu. So you will want to look for samples under "Menu" folder.

Just an additional note, you may want to avoid setting NavigateUrl on a top level item for slide menu. Normally slide menu would expand the corresponding slide pane when you click a top level item. However if you set that item's NavigateUrl, clicking the item would bring you to the new page instead of expanding the slide menu.

Additionally, when you use NavigateUrl with slide menu, you may also need to consider setting the following two properties:

http://www.essentialobjects.com/ViewDoc.aspx?t=EO.Web.BaseNavigator.AutoSelectSource.html
http://www.essentialobjects.com/ViewDoc.aspx?t=EO.Web.BaseNavigator.AutoSelectTarget.html

You would usually set the first one to NavigateUrl and the second one as Path. This helps you to automatically select an item based on the current page Url. Make sure you set SelectedStyle correctly when you use these two properties. Otherwise the item will be correctly selected, but the selected item will not look any different than any other items because it does not have a visually different SelectedStyle to apply.

Hope this helps.

Thanks
puffworld
Posted: Thursday, January 15, 2009 2:12:12 PM
Rank: Newbie
Groups: Member

Joined: 1/14/2009
Posts: 7
Hi Again.

I have one last question.

I'm building my sub menu with a loop... and I need a navigation url for each of the submenu items... the problem is it seems to have just the last one showing up.

See code below for what I'm doing:

UltraWebListbar1.Items.Add("Recent Searches")
Dim menuItem As EO.Web.MenuItem = UltraWebListbar1.Items.Item(o)
for k = 0 to 10
menuItem.SubItems.Add("RS - " & k)
menuItem.NavigateUrl = "/default.aspx?pageid=59&SearchID=" & k
menuItem.TargetWindow = "_self"
next

What is happening is on the main portion of the menu ... where it says Recent Searches is where the Navigation URL is linked not the submenu item.. RS - #

Any reason you can think of that it's doing that?

Thanks again for all your help.

Mary.

eo_support
Posted: Thursday, January 15, 2009 2:30:28 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
That's for sure. :) Inside your loop you added 10 child items but you set NavigateUrl of the parent item 10 times. You didn't touch the child item's NavigateUrl at all. You need to set each child item's NavigateUrl. The Add method you called inside your loop returns a MenuItem object that represents the newly added child item. So you can use that return value directly.

Hope this helps.

Thanks



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.