Cast error when creating menus

I’m trying to create menus , looked at the doco over and over for hours but cant seem to get a simple menu to work.

I have a menu bar on my page, and i have added a button in it called ContactsTBBtn
Then in the menu bar open handler i have the following.

Sub Open()
//Create the new menu
Dim toolBarMnu as New WebMenuItem
toolBarMnu.Append(New WebMenuItem(“Add Contact”))

//Assign the menu to the button in the toolbar
WebToolbarMenu(Me.ItemWithName(“ContactsTBBtn”)).Menu=toolBarMnu

End Sub

But i get a illegalCastException at Me.ItemWithName(“ContactsTBBtn”)

The error i get is WebToolBarButton cannot be cast to WebToolbarMenu.

Ok i get that, so we cant cast these two objects apparently, but the doco has this all over the place.

What am i doing wrong?

Anybody?

You put your code in the wrong open event?

Thanks Tim, any idea what open event i should use, I’ve tried two events , both against the toolbar object. I’ve tried the open event and the buttonAction() event, both give the same error.

Why don’t you try the page Shown event ?

//Create the new menu
Dim toolBarMnu as New WebMenuItem
toolBarMnu.Append(New WebMenuItem(“Add Contact”))

//Assign the menu to the button in the toolbar
WebToolbarMenu(Me.ItemWithName(“ContactsTBBtn”)).Menu=toolBarMnu

method me.itemwithname does not exist at the page level so i get an error.
I have put this code at the toolbar level in the open even as that is what the doco appeared to be suggesting.