How to automatically send the treenodecheckchanged event of the Treeview back to the server
ASP. NET
2.0 when the Treeview control is used, the treenode object (Treeview node) with the checkbox control is found. If the checkbox control is selected, the page cannot be sent back. In msdn, there is a comment on the Treeview. treenodecheckchanged event: "When
When the check box of the Treeview control changes the status between two sends to the server, the treenodecheckchanged
Event. This allows you to provide an event processing method, that is, to execute a custom routine (such as updating the database or displaying content) each time this event occurs ). Although treenodecheckchanged
The event is triggered during sending back, but changing the check box does not cause sending back ." The framework itself cannot provide a checkbox sending mechanism.
Although clicking checkbox does not cause sending back,
However, after the page is sent back, the treenodecheckchanged event is processed.CodeIt will be called, that is, if the checkbox click event is captured on the client,
Then use JavaScript to manually send back (dopostback), so that the checkbox can be automatically sent back.
However, when building a tree,
There is no way to define events on treenode, So we add this event to Treeview.
The demo is as follows:
This . Treeviewne. Attributes. Add ( " Onclick " , " Postbackbyobject () " );
This . Treeviewkpi. Attributes. Add ( " Onclick " , " Postbackbyobject () " );
Client step code// Trigger an event when you click the check box
Function Postbackbyobject ()
{
VaR O = Window. event. srcelement;
If (O. tagname = " Input " && O. Type = " Checkbox " )
{
_ Dopostback ("","");
}
}