Hi
I have a problem when i try to add a nodetemplate at runtime. Everythings works fine when i dot it in the page_init event but when i call the same function in the context menu event "ContextMenuItem_click" , the nodetemplate displays fine but when i click on a webcontrol (radioButtonList) not event is raise... ???
thanks is advance for your help. If you need more details on this case please let me know.
11 Answers, 1 is accepted
0
Dominic
Top achievements
Rank 1
answered on 25 Jun 2008, 06:55 PM
I forgot to say that the event that is not raise after adding the nodetemplate control is a dynamically added eventhandler in my user control. So, the only lead that i have is that i lost my handler in case i dont create the control in the page _init event.
Thanks
0
Hello Dominic,
You need to add the template after postback (before the state when ASP.NET framework is raising the postback events). Otherwise the control which triggered the postback won't be found and its postback events won't fire. You can do this in the Page_Load or Page_Init events. A simple solution would be to set some flag in viewstate during the NodeClick event (and add the template). Then check for this flag during Page_Init or Page_Load and if set to true - initilize the template again.
I hope this helps,
Albert
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
You need to add the template after postback (before the state when ASP.NET framework is raising the postback events). Otherwise the control which triggered the postback won't be found and its postback events won't fire. You can do this in the Page_Load or Page_Init events. A simple solution would be to set some flag in viewstate during the NodeClick event (and add the template). Then check for this flag during Page_Init or Page_Load and if set to true - initilize the template again.
I hope this helps,
Albert
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Dominic
Top achievements
Rank 1
answered on 26 Jun 2008, 02:49 PM
Hello, thanks for your answer
Maybe i've missed something. When i click on my context menu, the Page_init is raised, the Page_load after and the ContextMenuClick in last so how i can read the flag in the page_load (or init) if this event is not raised after the ContextMenuClick ???
Thanks for your help
0
Hi Dominic,
My idea is the following:
Albert
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
My idea is the following:
- The first time instantiate the template during the contextmenuitemclick event handler and raise the flag
- In subsequent postbacks instantiate the template in Page_Init/Load based on the flag.
Albert
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Dominic
Top achievements
Rank 1
answered on 26 Jun 2008, 05:29 PM
Hi , thanks for your answer.
Could you please send me a little code example because i'm not sure how your idea can satisfy my needs because when i click on my context menu, i need that the template to be add on the treeview immediatly....
Thanks a lot
0
Hi Dominic,
Here is some sample code:
I hope this helps,
Albert
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Here is some sample code:
| protected void RadTreeView1_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e) |
| { |
| InstantiateTemplate(e.Node); |
| ViewState["TemplatedNode"] = e.Node.Value; |
| } |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (ViewState["TemplatedNode"] != null) |
| { |
| RadTreeNode node = RadTreeView1.FindNodeByValue((string)ViewState["TemplatedNode"]); |
| InstantiateTemplate(node); |
| } |
| } |
I hope this helps,
Albert
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Dominic
Top achievements
Rank 1
answered on 27 Jun 2008, 01:37 PM
Hi, thanks for the sample.
When i apply your idea to my case it gives me the same result, the event in the usercontrol (nodeTEmplate) is not raised. I dont see how it can works because
when the user clicks on the context menu to add a node template, i add the usercontrol in the treeview, after that when the user click on the usercontrol wich is suppose to trigger the event the Page_load event is raised and the second instanciation is made but the user have already clicked on the node template and the user control never raise the event.
Tell me if my explanations are clear beacause im aware that my english is not very good so....
Thanks for your helps
0
Hello Dominic,
I am not sure what went wrong on your end. Please find attached a working sample page.
Regards,
Albert
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I am not sure what went wrong on your end. Please find attached a working sample page.
Regards,
Albert
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Dominic
Top achievements
Rank 1
answered on 27 Jun 2008, 07:56 PM
Hi,
On my side, i was using the Node.NodeTemplate property with the loadTemplate method instead of control collections of the node (with some other little differences). Whith the loadcontrol method its seems to works fine, but i think i'll have anyway to change my logic because if a user add a control to a node (he can have more than one control and node with 2 different usercontrols depending on the node level) and click on another after that, the flag in the viewstate will refers to the wrong node so the event will be triggered on the wrong control.
By the way, what's the difffence between the LoadControl and LoadTemplate, when we have to use wich one ?? I will really appreciate if you can show me some code for using the ITemplate approach.
Thank you very much for your help.
0
Accepted
Hello Dominic,
Using the Controls collection may be easier when you need to add controls from codebehind. Here you can check our help topic how to initialize node templates from codebehind.
The main difference between LoadTemplate and LoadControl is the return value. LoadControl returns a Control object which you can add in the Controls collection of some other control. The other returns ITemplate which you can set as the template of some control or use its InstantiateIn method.
Regards,
Albert
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Using the Controls collection may be easier when you need to add controls from codebehind. Here you can check our help topic how to initialize node templates from codebehind.
The main difference between LoadTemplate and LoadControl is the return value. LoadControl returns a Control object which you can add in the Controls collection of some other control. The other returns ITemplate which you can set as the template of some control or use its InstantiateIn method.
Regards,
Albert
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Dominic
Top achievements
Rank 1
answered on 01 Jul 2008, 12:36 PM
Ok, thank you very much for your helps. Great service....:)