I found a problem with the checkbox checked status when used in conjunction with another postback.
1st, the controls postback works fine on its own. Meaning if I check off checkboxes and then click a link on the tree view the checkbox state holds for the post back.
However I placed a button on the CheckboxTreeview.aspx page. When the button posts back I call GiveFeedback(); The following results are produced when the button is clicked (not a node)
| checked boxes | MessageLabel.Text |
| Musical | Action |
| Action | Jazz |
| Jazz | Acustic |
| Acustic | Eletric |
| Electric | [no text] |
here is the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link rel="stylesheet" href="SimpleTreeView.css" type="text/css" />
<link runat="server" rel="stylesheet" href="~/CSS/Import.css" type="text/css" id="AdaptersInvariantImportCSS" />
<!--[if lt IE 7]>
<link runat="server" rel="stylesheet" href="~/CSS/BrowserSpecific/IEMenu6.css" type="text/css" id="IEMenu6CSS" />
<![endif]-->
<!--[if gt IE 6]>
<link runat="server" rel="stylesheet" href="~/CSS/BrowserSpecific/IEMenu7.css" type="text/css" id="IEMenu7CSS" />
<![endif]-->
</head>
<body>
<form id="form1" runat="server">
<asp:TreeView ID="EntertainmentTreeView" runat="server"
OnSelectedNodeChanged="OnClick"
OnAdaptedSelectedNodeChanged="OnClick"
OnTreeNodeCheckChanged="OnCheckChanged"
OnAdaptedTreeNodeCheckChanged="OnCheckChanged"
CssSelectorClass="SimpleEntertainmentTreeView"
ExpandDepth="0"
ShowCheckBoxes="Leaf">
<Nodes>
<asp:TreeNode Text="Music" SelectAction="Expand">
<asp:TreeNode Text="Classical" />
<asp:TreeNode Text="Rock" SelectAction="Expand">
<asp:TreeNode Text="Electric" />
<asp:TreeNode Text="Acoustical" />
</asp:TreeNode>
<asp:TreeNode Text="Jazz" />
</asp:TreeNode>
<asp:TreeNode Text="Movies" SelectAction="Expand">
<asp:TreeNode Text="Action" />
<asp:TreeNode Text="Drama" />
<asp:TreeNode Text="Musical" />
</asp:TreeNode>
</Nodes>
</asp:TreeView>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<div id="EntertainmentMessage">
<asp:Label id="MessageLabel" runat="server" />
</div>
</form>
</body>
</html> public void OnClick(Object sender, EventArgs e)
{
GiveFeedback();
}
public void OnCheckChanged(Object sender, TreeNodeEventArgs e)
{
GiveFeedback();
}
public void GiveFeedback()
{
MessageLabel.Text = "";
if (EntertainmentTreeView.SelectedNode != null)
{
MessageLabel.Text += "You selected " + EntertainmentTreeView.SelectedNode.Text + ".";
}
if (EntertainmentTreeView.CheckedNodes.Count > 0)
{
MessageLabel.Text += "<br /><br />The checked values are:<ul>";
foreach (TreeNode item in EntertainmentTreeView.CheckedNodes)
{
MessageLabel.Text += "<li>";
MessageLabel.Text += item.Text;
MessageLabel.Text += "</li>";
}
MessageLabel.Text += "</ul>";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
GiveFeedback();
}