Hi,
On the attached sample you will find a website where by clicking on the top botton a node with the textbox's text is added to a tree. You can add as many as you want.
The problem comes when you check some nodes and then click the button on the bottom which on its handler counts the checked nodes.
After the postback, the checkboxes text disappears.
The reason why We are using Template is because we want only some nodes to have a checkbox but not all of them so CheckBoxMode is not adequate.
Can you give me any advice?
Thanks in advance.
Hello rickycl ,
The first time you add the new node you do it on a button click event during which the creation of the template is initialized and the values are set as expected.
Then I think that the node values are persisted in the view state until you make changes to checkbox state. Then on Init the values for the nodes are not yet available.
So you’ll need access them later in the page life cycle.
The issue in this case is not the template itself since it initializes and behaves as expected. It’s the node values that are not yet available on Init. If you set a static value for the text or a value that is available in this early stage of the page lifecycle it will work as expected. Still if you need to set values such as the text of the node it would be best to access them after the initialization has completed and the values have been properly populated. That would be any event after Init.
I hope this was helpful. Let me know if you still have any questions.
Best Regards,
Maya Kirova
Developer Support Engineer
Infragistics, Inc.
http://es.infragistics.com/support
Hello Maya,
Sorry for the late response.
I tried your suggestion and it worked fine, even though, I still have two doubts:
- Why did the text only dissappear when there was not checked checkboxes ? (if you do not check any of them it will work fine)
- What is the recommended approach when using controls with templates like this one? I mean, do I have to always handle Page_Load event and set properties like text again? We would prefer we didn't.
Thank you very much.
I'm just following up to see if you have any further questions or concerns.
If so don't hesitate to contact me.
It seems that in this case over postback the value/text field of the nodes are not yet populated when initializing the templates. What you can do is iterate trough the nodes collection get that template and set the checkbox’s text later in the page life cycle for example on Page_Load. For example:
protected void Page_Load(object sender, EventArgs e)
{
foreach (DataTreeNode item in WebDataTree1.Nodes)
item.EnsureTemplate();
CheckBox customCheckBox = (CheckBox) item.FindControl("CustomChBox");
customCheckBox.Text = item.Text;
}
Please refer to the attached sample and let me know if need further assistance with this issue or if you have any further questions.
Sorry about that, already edited the post.
Thanks!