views:

263

answers:

2

hi

I have a treeview, and already the javascript code to postback the page. Because when i select the father , auto-select the children.

this is my html code

<script>
                                function postBackCheckBox()
                                {
                                    var o = window.event.srcElement;
                                    if (o.tagName == 'INPUT' && o.type == 'checkbox' && o.name != null && o.name.indexOf('CheckBox') > -1)
                                    {
                                        __doPostBack('LinkButton1', '');
                                    }
                                }
                            </script>

                            <asp:UpdatePanel UpdateMode="Conditional" ID="UpdatePanel1" runat="server">
                                <ContentTemplate>
                                    <asp:TreeView ID="HierarchicalTreeView" runat="server" OnSelectedNodeChanged="HierarchicalTreeView_SelectedNodeChanged"
                                        ShowLines="True" ExpandImageToolTip="Fechar &quot;{0}&quot;" CollapseImageToolTip="Fechar &quot;{0}&quot;"
                                        ExpandDepth="1" OnTreeNodeCheckChanged="HierarchicalTreeView_TreeNodeCheckChanged"
                                        EnableClientScripts="true">
                                        <NodeStyle CssClass="text" />
                                        <SelectedNodeStyle CssClass="text" Font-Bold="true" />
                                    </asp:TreeView>
                                </ContentTemplate>
                                </asp:UpdatePanel>
                            <asp:LinkButton ID="LinkButton1" runat="server" Visible="false"></asp:LinkButton>

and in C#

HierarchicalTreeView.Attributes.Add("onclick", "postBackCheckBox()");
ScriptManager scripManager = (ScriptManager)Page.Master.FindControl("ScriptManagerMaster");
scripManager.RegisterAsyncPostBackControl(LinkButton1);

How can i prevent from postback all page, and only the treeview???, so dont 'refresh' the page

+1  A: 

You need to use Ajax for this, e.g. place your treeview in UpdatePanel.

Try calling __dopostback function like this:

 __doPostBack('<%= LinkButton1.ClientID %>', '');
Andrew Bezzub
you can post your updated code here
Andrew Bezzub
Try change the way you are calling __doPostBack
Andrew Bezzub
Its because linkbutton is not in the updatepanel. Try placing it inside of the panel.
Andrew Bezzub
Still not postback only the treeview.. Updated the code in the top
Luis
did with succes with this version, but now is always collapsing the nodes
Luis
A: 
<asp:UpdatePanel UpdateMode="Conditional" ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:TreeView ID="HierarchicalTreeView" runat="server" OnSelectedNodeChanged="HierarchicalTreeView_SelectedNodeChanged"
            ShowLines="True" ExpandImageToolTip="Fechar &quot;{0}&quot;" CollapseImageToolTip="Fechar &quot;{0}&quot;"
            ExpandDepth="10" 
            OnTreeNodeCheckChanged="HierarchicalTreeView_TreeNodeCheckChanged" 
            ontreenodeexpanded="HierarchicalTreeView_TreeNodeExpanded">
            <NodeStyle CssClass="text" />
            <SelectedNodeStyle CssClass="text" Font-Bold="true" />
        </asp:TreeView>                                                                     
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="buttonCheck" EventName="click" />
    </Triggers>
</asp:UpdatePanel>

<asp:button ID="buttonCheck" runat="server" CausesValidation="false" />

C# code

 buttonCheck.Attributes.CssStyle["visibility"] = "hidden";
            HierarchicalTreeView.Attributes.Add("onclick", string.Format("document.getElementById('{0}').click();", buttonCheck.ClientID));
            ScriptManager scripManager = (ScriptManager)Page.Master.FindControl("ScriptManagerMaster");
            scripManager.RegisterAsyncPostBackControl(buttonCheck);
Luis