如果在TreeNode
控件中选中了TreeView
复选框,如何自动回发到服务器?
答案 0 :(得分:3)
您可以使用简单的javascript
添加此行为你应该查看这篇文章 http://forums.asp.net/p/1109288/1888180.aspx
<script language="javascript" type="text/javascript">
function postBackByObject()
{
var o = window.event.srcElement;
if (o.tagName == "INPUT" && o.type == "checkbox")
{
__doPostBack("","");
}
}
</script>
答案 1 :(得分:0)
使用jQuery使事情变得现代化:
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:TreeView ID="TVP" runat="server">
...
</asp:TreeView>
<asp:Button ID="BTVPNC" runat="server" style="display: none;" />
</ContentTemplate>
</asp:UpdatePanel>
后面的VB.NET代码:
Private Sub TVP_PreRender(sender As Object, e As EventArgs) Handles TVP.PreRender
Dim js As String = "$('#" + Me.TVP.ClientID + "').find('input[type=""checkbox""]')"
js += ".bind('change',function(){" + Me.ClientScript.GetPostBackEventReference(Me.BTVPNC, "") + ";});"
ScriptManager.RegisterStartupScript(Me.TVP, Me.TVP.GetType(), "TVP_NodeCheckAutoPostBack", js, True)
End Sub
Private Sub TVP_TreeNodeCheckChanged(sender As Object, e As TreeNodeEventArgs) Handles TVP.TreeNodeCheckChanged
'Handle your TreeView NodeChecked with AutoPostBack event here.
End Sub