Hello,
since the expanding and selection of a submenu-item (my other post) in code behind (for ex. there are four levels and fourten nodes
A1000 -- A1100 -- A1110 -- A1111
| | -- A1112
| | -- A1113
| -- A1200 -- A1210
| -- A1220
| -- A1230
| -- A1240
B1000 -- B1100
C1000
is on the way to a never ending story (no solution realy work), i am looking for an other solution. My problem: each node in my example should load some content in a textarea, if the user select the node (or item); so if i click on A1200 --> expand the submenu (A1210, ...), load the contetent for 'A1200' and don't close the menu (stay where you are).
My first try was to sent the item-click to the server; in the item-value of the menu, i store the id of the record that i load via datareader and bind to the textarea.text.
But there is a postback and the mneu is closed. I found no way to open in code behind!
So is there a way to open/expand the menu to a special node (A1200 ??) on page load?
Any better solution??
Thanks
Patric
I am 100% sure what you are tyring achieve. Can't understand where is that text area - is it in the MenuItemTemplate or is it a separate control on the page. But the cleanest solution for me is to use the Client Side API for WebDataMenu. There is open method that each DataMenuItem has. So, when you load the content for your text area, you may want obtain an instance of WebDataMenuItem and then call its open method. This will cause the opening of the full path to where that item is (regardless of how deep it is in the menu hierarchy). You could use the resolveItem(address) method of the WebDataMenu client object to get instance of the item you wish to open. Other way of obatining an instance of WebDataMenuItem that you need to open after loading the content for your textarea is to handle the client side Click event of the WebDataMenu. The handler shall have two parameters:
function wdmItemClick(menu, eventArgs) { ... }
The eventArgs has method "getItem()" which will give direct reference to the client object instance for the clicked item. You can set it to a globally scoped variable and just call the open() method of that globally scoped variable when your content loads.
The main point is that you can't have menu staying opened when it loses focus. If your content loads fast enough, and you call open(), the menu may still stay openened. You can control to some extend the behavior. You may first want to set the CloseMenuOnClick property to false, then adjust the SubMenuClosingDelay to some higher value (value is in milli seconds) to keep the submenus opened for longer after losing focus (you want it to stay open during your content loading and after that).
Hope this helps!
Hello Anton,
first of all thanks for your fast and very detailed explanation. I try it and give you a feedback of my results.
I think i must my description more clear. I store the hierachical structure of the menu in a Sql Server table, load it via SqlDatasource and use the infragistics hierarchical datasource for the menu. The value - prop of each menu-item is used as the id-field of a row in an other table. In this table is some content stored (the text for the text area, a link for an image, ...). This content is loaded via datareader and i catch the value of the Clicked-item on server (code behind). The page uses two parts; one for the content, one for the menu. Click a menu item, then load and display the content and let the menu open. Sounds simple, right? But i can not open the menu in code behind; so i try to use the page load and the client side code.
You can take a look at http://www.sternenweg.net/detailseite.aspx
OK, the hints of Anton point me in the right direction. Since this is a 'solution' for a small project, i don't want any additional work, so i let the item click do the postback. I now catch the valu on server side (you know, my id for the content-row), but in addition, i 'missused' the target prop. In the 'Menu-Table' on the database, i use this to store the 'adresse' of the item. From my intial example A1230 is '0.1.2' and C1000 is '2'. This value used in the menu initalized event, and i can handle all i need. I know, this is far from perfect (i should use only client side code and load the content via a service and so on. But for me it works.
Here is the code snipet:
On the server:
protected void wdm_Item_Click(object sender, Infragistics.Web.UI.NavigationControls.DataMenuItemEventArgs e)
{
string sSeite = e.Item.Value;
hf_Menu.Value = string.IsNullOrEmpty(e.Item.Target) ? "0" : e.Item.Target; // in Target ist die Adresse kodiert
//hf_Menu.Value = "1.0.1";
if (int.TryParse(sSeite, out iSeite)) // iSeite is a global variable, i use in the Loader; better a parameter for the prodedure
Lade_Daten();
}
On Client
<asp:HiddenField ID="hf_Menu" runat="server" Value="0" />
function wdm_Menu_Init(sender, args) {
var adresse = $("[id$='hf_Menu']").val()
var Item1 = sender.resolveItem(adresse);
Item1.open();
Cool!
I'm glad you've solved your issues!
the happiness was to early! I now have a strange effect: All seems to work correct, but after the third selection, the menu don't open. In addition it looks like the 'expand on hover' for the parent item is false; so even if i hover the parent item, this branch does not open anymore. But other branches open, so it is not a problem of the whole menu.
You can find my test on:
http://www.sternenweg.net/detailseite.aspx
If you hover 'Sternenweg - Philosophie - Das Projekt' and click, there is a postback, content loads, menu open. Then you click on 'Sternenweg - Wegeverlauf', content load, menu don't open and the branch 'Sternenweg' don't open on hover anymore.
But if you hover 'Sprachen', this submenu opens. Even if i reload the page on the same browser, the 'Sternenweg' branch is frozen. May be the browser cached some structure and i must rebuild this?
So any solution how to fix this??
Hello Anton, i don't understand, that you don't have this effect. I test it again on IE 9, FF 14 with Win 7 Ultimate x64 and Vista. Two clicks on the branch 'Sternenweg', it expand never more. But i checked the nodes with some Firefox Tools and it seems, that the node 'Sternenweg' is in the ItemSelected Collection and the other nodes aren't. Is this a caching problem? So if the Initialize event on the client is fired aifter a postback, is it shure that the whole structure is rebuilded new? Or looks the control in the client cache and try to rebuild from cache? Or from viewstate, or Ajax-viewstate ???
But If it works for you (no freezing), how can this happen. This points to a problem in the Client Environment, but i test with and without proxy, same result.
Is there a way to destroy the menu (release the cache or so on) and rebuild it from server?
you are 100% right, that an Ajax-solution would be better, but sometimes you go in one direction (the quick and dirty way) and on the way you realize there is e better way. And than you can choose this better way or think 'No, i want to stay on my way; there must be a solution too'. I know that's sometimes stupid.
Again,
thanks for our help,
Hi,
It is good that you solved your issues. However, looking at your other post (http://es.infragistics.com/community/forums/t/71197.aspx), I have commented at the bottom, that it might be a better idea to have everything more AJAX style and handle everything on the client side. For example - handle the client Click event, not the server one. Then load the content cia AJAX, and finally prevent the menu from closing, by cancling the ItemCollapsing client side event. I think this way you will achieve much better user experience, and it is not that complex to implement. I would say maybe even easier than what you did now.
Cheers,
it is as i expected, the problem is the 'selected_item' collection. I found no way on client side to clear this collection. So i do the hard way on server side; Menu.Databind()!
And all works fine.
if (int.TryParse(sSeite, out iSeite))
WebDataMenu2.DataBind(); }
The final hint in this direction came from my other post: http://es.infragistics.com/community/forums/t/71197.aspx
if (sender.get_selectedItem() != null) {
alert(sender.get_selectedItem().get_valueString());
// to heavy !! sender.get_selectedItem().dispose();
// no result !! sender.get_selectedItem().set_selected(false);
// works, but also freeze!! sender.get_selectedItem().open();
//alert(adresse);
Not a real solution, but a workaround for me!