This is a migrated thread and some comments may be shown as answers.

CheckedNodes returning empty list after submit button is clicked

1 Answer 94 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 11 Jul 2008, 03:51 PM

Hi Everyone,

I'm using a RadTreeView with checkboxes enabled. I would like to persist the checked state of nodes to a new page that I POST to:

<asp:Button ID="PreviewButton" Text="Preview" OnClick="BtnPreview_click" PostBackUrl="<b>SomeNewPage.aspx</b>" runat="server" />

To do this, inside the BtnPreview_click method, I want to get the value of all of the checked nodes and serialize/store them in a string that I can access from the new posted page (via cross-page posting).

The BtnPreview_click method is as follows:

protected void BtnPreview_click(object sender, EventArgs e) { 
    // Get the RadTreeView (called "folderView") 
 
    IList<RadTreeNode> checkedNodes = folderView.CheckedNodes;  
 
    // Do some stuff with the nodes 
However, the value of folderView.CheckedNodes is always empty (Count == 0). I've verified that the tree view nodes are populated at this point (albeit, programmatically). 

One other thing to note: this is posting to a new page so I put some breakpoints to see the program flow. When I click the Preview button, I get to Page_Load of the current page (which indicates that the page does a post back before sending me to the new page??), after which the BtnPreview_click(...) method is called, and then finally the Page_Load of the new page is called.

Does anyone know why folderView.CheckedNodes is empty?

Thanks,
Ryan

1 Answer, 1 is accepted

Sort by
0
Ryan
Top achievements
Rank 1
answered on 11 Jul 2008, 05:19 PM
I found the problem. The tree was being populated in Page_Load, not Page_Init. Moving the setup code into Page_Init preserved all post back state.

Thanks,
Ryan
Tags
TreeView
Asked by
Ryan
Top achievements
Rank 1
Answers by
Ryan
Top achievements
Rank 1
Share this question
or