I am working with Treeview
control and I am using the following code
<asp:TreeView ID="tvCategories" ShowCheckBox="False" Style="font-family: Trebuchet MS;
margin-top: 5px; margin-bottom: 5px; margin-left: 20px; color: Black; font-size: 12px"
runat="server" ShowLines="true" NodeIndent="5" OnTreeNodeCheckChanged="tvCategories_TreeNodeCheckChanged"
OnSelectedNodeChanged="tvCategories_SelectedNodeChanged">
<LeafNodeStyle ForeColor="#555555" />
<ParentNodeStyle ForeColor="Black" />
<RootNodeStyle ForeColor="Black" />
</asp:TreeView>
Both the OnTreeNodeCheckChanged
and OnSelectedNodeChanged
are not working and the AutoPostBack
property is not available for Treeview
.
Please help me out with this issue. Thanks
You need use javascript to make the page postback, then the treenodecheckchanged event can be fired.
like below, you should add the code of bolder to make the page postback.:
<script language="javascript" type="text/javascript">
function postBack()
{
var element = window.event.srcElement;
if (element .tagName == "INPUT" && element.type == "checkbox")
{
__doPostBack("","");
}
}
</script>
Add the above javascript code in the head section of the page.
onclick="javascript:postBack()"
There is no AutoPostBack
property for TreeView.
As per the MSDN:
The TreeNodeCheckChanged
event is raised when a check box in the TreeView
control changes state between posts to the server. This allows you to provide an event-handling method that performs a custom routine, such as updating a database or the displayed content, whenever this event occurs.
You can try javascript to postback the page by adding the onclick event.
Reference: PostBack on selecting checkbox of treeview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With