CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 5/10/2007 8:03:22 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 8 Views: 527 Favorited: 0 Favorite
9 Items, 1 Pages 1 |< << Go >> >|
yaoliu
Asp.Net User
Asp.Net 2.0 Treeview - How to AutoPostback when a TreeNode's checkbox gets checked?5/10/2007 8:03:22 PM

1

My requirement is quite simple:

  1. Show an organizational hierarchy in a treeview. for example, company -> department1, department2 etc,  Every treenode has a checkbox displayed next to it.
  2. Whenever the parent node is checked, all its child nodes will get checked as a result of it. I want to handle this event on the server side.
#1 is easy to do, but I can't figure out how to do #2 because there is no event gets fired for the checkbox click. Is there any way to fire this event to the server? Any help is greatly appreciated!!!
Amanda Wang - M
Asp.Net User
Re: Asp.Net 2.0 Treeview - How to AutoPostback when a TreeNode's checkbox gets checked?5/14/2007 3:36:43 AM

0

Hi,

 In the treeView you can use the TreeNodeCheckChanged event for the checkbox click.

In the MSDN's  TreeView.TreeNodeCheckChanged Event , you could get more inforamtion.

if you find the the treeview could not PostBack, I am afraid you should require javascript. Below is a simple example:

<script language="javascript" type="text/javascript">

function postBackByObject()
{
    var o = window.event.srcElement;
    if (o.tagName == "INPUT" && o.type == "checkbox")
    {
       __doPostBack("","");
    }
}
    </script>

 <asp:TreeView ID="TreeView1" EnableClientScript="true" onclick="javascript:postBackByObject()"  runat="server" DataSourceID="SiteMapDataSource1" LineImagesFolder="~/TreeLineImages" ShowLines="True" OnTreeNodeDataBound="TreeView1_TreeNodeDataBound" OnTreeNodeCheckChanged="TreeView1_TreeNodeCheckChanged" ShowCheckBoxes="All">


Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Yours sincerely,
Amanda Wang
Microsoft Online Community Support
freeborn5
Asp.Net User
Re: Asp.Net 2.0 Treeview - How to AutoPostback when a TreeNode's checkbox gets checked?5/16/2007 6:31:38 PM

0

 Thanks So much I was stumped on this the javascript works like a charm

yaoliu
Asp.Net User
Re: Asp.Net 2.0 Treeview - How to AutoPostback when a TreeNode's checkbox gets checked?5/29/2007 5:06:21 PM

0

 Thanks a lot, Amanda, that will work.

jeny_p
Asp.Net User
Re: Asp.Net 2.0 Treeview - How to AutoPostback when a TreeNode's checkbox gets checked?7/3/2007 12:18:00 PM

0

Hi, I have the same problem but this code didn't work for me and I got the warning "Attribute onclick is not a valid attribute of element TreeView"

What might the problem be?

thanks

VinBrown
Asp.Net User
Re: Asp.Net 2.0 Treeview - How to AutoPostback when a TreeNode's checkbox gets checked?7/19/2007 12:26:30 PM

0

Amanda, you are awesome. I needed a quick solution to this problem and this worked great.

abcpaem
Asp.Net User
Re: Asp.Net 2.0 Treeview - How to AutoPostback when a TreeNode's checkbox gets checked?8/24/2007 8:54:54 AM

0

Thank you, Amanda, for your post, I just would change two little things in order to make it compatible with other navigators (Firefox, etc..):

function postBackByObject(mEvent)
{
    var o;
    // Internet Explorer    
    if (mEvent.srcElement)
    {
        o = mEvent.srcElement;
    }
    // Netscape and Firefox
    else if (mEvent.target)
    {
        o = mEvent.target;
    }
    if (o.tagName == "INPUT" && o.type == "checkbox")
    {
       __doPostBack("","");
    } 
}

and add the event parameter to the fucntion call: onclick="javascript:postBackByObject(event)"

Thanks a lot!

Patrick.

abcpaem
Asp.Net User
Re: Asp.Net 2.0 Treeview - How to AutoPostback when a TreeNode's checkbox gets checked?8/24/2007 4:16:31 PM

0

Hi again,

After doing what Amanda suggested, the next step was to wrap my TreeView control with an Ajax UpdatePanel in order to do Asynchronous postbacks and refresh only the Treview control, it was then when I realized that with Ajax I didn't need the Amanda's postBackByObject approach anymore, I just attached a trigger from the UpdatePanel to a hidden button and that's it!, the button will do the Postback. See the code below:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">                        
    <ContentTemplate>
         <asp:TreeView ID="TreeViewMenu" runat="server" DataSourceID="XmlDataSourceMenu" ShowCheckBoxes="All" BorderWidth="3px" BorderColor="White" NodeStyle-ForeColor="#5982A2" OnTreeNodeDataBound="TreeViewMenu_TreeNodeDataBound" OnPreRender="TreeViewMenu_PreRender" OnTreeNodeCheckChanged="TreeViewMenu_TreeNodeCheckChanged">
                <DataBindings>                            
                     <asp:TreeNodeBinding DataMember="Menu" TextField="Name" Depth="0" SelectAction="None" ValueField="Id" />
                      <asp:TreeNodeBinding DataMember="Submenu" TextField="Name" Depth="1" SelectAction="None" ValueField="Id" />
                </DataBindings>
                <NodeStyle ForeColor="#5982A2" />
         </asp:TreeView>
         <asp:XmlDataSource ID="XmlDataSourceMenu" runat="server" DataFile="~/_resources/Menu.xml" XPath="//Menu" TransformFile="~/_resources/Menu.xslt">
         </asp:XmlDataSource>
   </ContentTemplate>
   <Triggers>
      <asp:AsyncPostBackTrigger ControlID="buttonCheck" EventName="click" />
   </Triggers>
</asp:UpdatePanel>

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

and the code behind is:

buttonCheck.Attributes.CssStyle["visibility"] = "hidden";
TreeViewMenu.Attributes.Add("onclick", string.Format("document.getElementById('{0}').click();", buttonCheck.ClientID));

 Of course there is no need to say that you must have an ScriptManager control for Ajax to work.

Patrick.

Omkar Lale
Asp.Net User
Re: Asp.Net 2.0 Treeview - How to AutoPostback when a TreeNode's checkbox gets checked?9/1/2007 12:31:33 PM

0

Hi amanda and patrick,

Thanks a lot

I was facing this same problem of treeview.

I had tried out with what you both had suggested. And its working perfectly fine.

I am now using the code that patric had suggested since it doesn't not flash the page due to ajax.

Thanks again

Omkar

 

9 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
ASP.NET 2.0: Your Visual Blueprint for Developing Web Applications Authors: Chris Love, Pages: 339, Published: 2007

Web:
Asp.Net 2.0 Treeview - How to AutoPostback when a TreeNode's ... Asp.Net 2.0 Treeview - How to AutoPostback when a TreeNode's checkbox gets checked? Rate It (1). Last post 09-01-2007 8:31 AM by Omkar Lale. ...
Treeview autopostback - ASP.NET Forums Treeview autopostback. Last post 05-02-2008 10:28 AM by Suprotim Agarwal. 1 replies. Sort Posts: ... tagName == 'INPUT' && o.type == 'checkbox' && o.name ! ... 0) { foreach (TreeNode tn in node.ChildNodes) { tn.Checked = check; ... Page 1 of 1 (2 items) ... Channel 10: Go Retro: Get Windows 98 Themes for Windows 7 ...
Treeview and checkboxes problem Feb 17, 2004 ... I try to set programmatically treeview checkboxes. ... Checked = False End If For k = 0 To tvFilters.Nodes(i).Nodes. ... Height="40px" AutoPostBack="True"> < asp:ListItem ... ... Get these publications absolutely FREE for up to 12 months. ...
checkboxes in treeview if i select the 'checkbox' option,then i'll get check boxes even ... the check of each checkbox set autopostback property of treeview to true. ... Dim newNode1 As TreeNode = New TreeNode() newNode1. ... The Javascript Code snippet is as follows:- ... inputs[0].checked = checkedState; ...
CodeProject: ASP.NET TreeView Control & the Client's Browser. Free ... For example, I would store meta-data in a tree node s NodeData property as follows: ..... NodeData is not a property of TreeView in ASP.NET 2.0, and after reading all the .... Currently the state of any nodes that get checked using client scripts (e.g. ... I want to disable (AutoPostBack) for the tree . So on the ...

Asp.Net 2.0 Treeview - How to AutoPostback when a TreeNode's ... Asp.Net 2.0 Treeview - How to AutoPostback when a TreeNode's checkbox gets checked?, > ROOT > NEWSGROUP > Asp.Net Forum ... For example, I would store meta -data in a tree node s NodeData property as follows: . ...






treeview nodes change there color when losing focus

custom node in tree view control

toobar button invisible at runtime

ie web controls with framework v1.0.3705

adding webcontrols to visual studio 2002 toolbox

microsoft.web.ui.webcontrols.dll

how to tell if a tab is selected in a tabstrip

adding nodes to treeview programatically

problem with rendering of tabstrip in updatepanel, which will be load on async postbak...

treeview and multipage problem

can i install the new web controls on my local machine

tabstrip state error

multipage event handling

treeview newbie questions

webctrl_client folder inetpub/wwwroot..is there anyother way?

ie webcontrol, tool tip for every node in the treeview

asp.net site for all browsers

installing treeview control on server 2003

treeview fails over the internet with .net 1.1

installation problem !

404 errors in log file from using treeview

multipage/tabstrip dynamic usercontrol dilemma

tabstrip, multipage and windows 2000 server

why my iewebcontrols.msi can't be installed

disabling node expansion

tabstrip borders

treeview does not show a tree, just plain string of text

microsoft.web.ui.webcontrols.dll not generated

persist multipage pageview contents?

treeview ie web control

   
  Privacy | Contact Us
All Times Are GMT