CodeVerge.Net Beta


   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: > Asp.Net Forum > microsoft_downloads.css_friendly_control_adapters Tags:
Item Type: Date Entered: 11/28/2006 1:28:12 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 3 Views: 120 Favorited: 0 Favorite
4 Items, 1 Pages 1 |< << Go >> >|
"Russ Helfand"
NewsGroup User
TreeView.SelectedNode, when is it set???11/28/2006 1:28:12 PM

0

Thomas from Germany has been helping spread the word that the adapters have hit RTM, http://blog.thomasbandt.de/de/aspnet/aspnet-2/aspnet-20-css-friendly-control-adapters-10.aspx.

Unfortunately one of Thomas' readers encountered a problem:

Albert Weinert meint: (23.11.2006 13:47:00)
Leider ist das TreeView nicht zu gebrauchen, da die SelectedNode weg ist sobald ein Postback ?ber was anderes als das TreeView ausgel?st wird. Problem ist bekannt, nicht behoben.

Basically this reports that the SelectedNode property of the adapted TreeView control improperly is null in the Load event for the Page.

I have confirmed this problem.  The TreeViewAdapter is not setting the value of the SelectedNode property until its override of the RaisePostBackEvent method is called. This may reveal a very simple workaround for many developers.  Let me explain.

Install the latest (RTM) version of the adapter kit.  In Visual Studio, create a new web site using the template called ASP.NET CSS Friendly Web Site.  Replace the contents of WalkThru\SimpleTreeView.aspx with the following:

<%@ Page Language="C#" %>

<script runat="server">
    protected TreeNode FindSelectedNode(TreeNodeCollection nodes)
    {
        if (nodes != null)
        {
            foreach (TreeNode node in nodes)
            {
                if (node.Selected)
                {
                    return node;
                }
                TreeNode childNode = FindSelectedNode(node.ChildNodes);
                if (childNode != null)
                {
                    return childNode;
                }
            }           
        }
        return null;
    }
   
    protected void FixTreeView(TreeView treeView)
    {
        if (treeView != null)
        {
            TreeNode selectedNode = FindSelectedNode(treeView.Nodes);
            if (selectedNode != null)
            {
                selectedNode.Select();
            }
        }
    }
   
    public void Page_PreRender(Object sender, EventArgs e)
    {
        MessageLabel1.Text = EntertainmentTreeView.SelectedNode == null ? "Null" : EntertainmentTreeView.SelectedNode.Text;
        FixTreeView(EntertainmentTreeView);
        MessageLabel2.Text = EntertainmentTreeView.SelectedNode == null ? "Null" : EntertainmentTreeView.SelectedNode.Text;
    }
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <link rel="stylesheet" href="SimpleTreeView.css" type="text/css" />
    <link runat="server" rel="stylesheet" href="~/CSS/Import.css" type="text/css" id="AdaptersInvariantImportCSS" />
<!--[if lt IE 7]>
    <link runat="server" rel="stylesheet" href="~/CSS/BrowserSpecific/IEMenu6.css" type="text/css" id="IEMenu6CSS" />
<![endif]-->
</head>
<body>
    <form id="form1" runat="server">
        <asp:TreeView ID="EntertainmentTreeView" runat="server" CssSelectorClass="SimpleEntertainmentTreeView" ExpandDepth="0">
            <Nodes>
                <asp:TreeNode Text="Music" SelectAction="Expand">
                    <asp:TreeNode Text="Classical" />
                    <asp:TreeNode Text="Rock">
                        <asp:TreeNode Text="Electric" />
                        <asp:TreeNode Text="Acoustical" />
                    </asp:TreeNode>
                    <asp:TreeNode Text="Jazz" />
                </asp:TreeNode>
                <asp:TreeNode Text="Movies" SelectAction="Expand">
                    <asp:TreeNode Text="Action" />
                    <asp:TreeNode Text="Drama" />
                    <asp:TreeNode Text="Musical" />
                </asp:TreeNode>
            </Nodes>
        </asp:TreeView>
       
        <div>
            <asp:Button runat="server" UseSubmitBehavior="true" Text="Submit" />
        </div>
       
        <div id="EntertainmentMessage">
            <asp:Label id="MessageLabel1" runat="server" />
            <br />
            <asp:Label id="MessageLabel2" runat="server" />
        </div>
    </form>
</body>
</html>

There are a couple of things to note in this sample.  If you do things in Page_PreRender and you call FixTreeView then the TreeView's SelectedNode is correct.  That may provide some immediate relief for the problem.

The real fix is probably to put something like FixTreeView into the adapter itself at the right point in its lifecycle.  That's going to take a little more work and thinking.  Can anyone confirm this workaround? Does anyone care to continue suggest where in the adapter's lifecycle we should do this fix-up?  Should we be handling SelectedNode in the TreeViewAdapter in a very different way?


Russ Helfand
Groovybits.com
"Albert Weinert
NewsGroup User
Re: TreeView.SelectedNode, when is it set???11/29/2006 9:22:59 AM

0

Hello Russ,

thank you for you help, but this workaround don't work. It works for the PreRender, but this is a much to late to normale Page LifeCycle.

I try to describe the problem. On the Page is a TreeView and a Button, if i selected a Node in the TreeView then in the SelectedNodeChanged-Event then the SelectedNode is correct. Now i press the Button and within the the Click-Event the SelectedNode of the TreeView is null. But it is visualy selected in the TreeView. Sometimes after the Click-Event the Page.PreRender-Event is called, and this little "fix" manually set the selectedNode. After that everything is fine, but to late.

In my case i can now "override" the SelectedNode property and call the recursive Search for getting the Node. But this seems not to be a good fix :)
 


"Tomáš Studva"
NewsGroup User
Re: TreeView.SelectedNode, when is it set???1/3/2007 6:47:05 PM

0

Hi,

I've encountered the same problem with SelectedNode == null. I think the presented workaround is ineffective, but working. The right place for FixTreeView() call is loadpostdata() in TreeAdapter.

I have this scenario:

tree is rendered, then by click node can be selected (page is postbacked) and later by another click(page is postbacked) the SelectedNode  is read.

So it is important, that in every post back, the property SelectedNode is set and before onLoad. So there are two possibilities: in LoadViewState or LoadPostData. In LoadAdapterViewState() it doesn't works. In LoadPostData it is working.

In original TreeView is used hidden field to store selected node index. And in loadpostdata, the index is used to select the node. The stored selected node index is TreeNode.Index - internal property. For performance reasons it could be done the same style - using hidden field.

 Tomas

 

"Tomáš Studva"
NewsGroup User
Re: TreeView.SelectedNode, when is it set???2/23/2007 8:40:30 PM

0

A similiar bug (I think there is such bug, but don't know it for 100%) is with not raising selectedNodeChangedEvent. The workaround is same using fix treeview. The time to call must be before TreeViewAdapter.RaisePostBackEvent(). So appropriate time is as was said in method: TreeViewAdapter.LoadPostData().
4 Items, 1 Pages 1 |< << Go >> >|


Free Download:













what its mean by this error

embed resource

gridview template

refresh the page using javascript?

httpcontext.current.request.url.getleftpart(uripartial.authority) from dll

session and global.asax across applications

will return immediately return?

checkboxes

autogenerate formview templates

strategy for a career in asp.net

newbie code question

how to move the site from personal server to production server

problem with datarow and datetime....

profile & accessdatasource ???

using class to communicate with hllapi enabled app with asp.net 2.0

linking news on default page

changing objectdatasource defaultvalue at runtime

asp.net version 1.1 not raning why?

existing a sub

data formats

can asp.net web services return json object?

converting double to int

unable to create new project

advice on proper control to use

class not registered - error

error help needed

online hosting

sharing a dll across apps without using gac.

guid

i added email to my site but!!!

a few newbie questions, slightly more advanced.

what is [webmethod]

how can we stop a worker process manually in code

standards, compatability, (can of worms)...

need help

how do you have your iis directory structure configured?

creating a .csv file in text format

check internet availability from .net windows application

using class file as include file of functions...

downloading a word doc

if only one textbox in start step of a wizard control, the next button doesn't handle return

making changes to site that is running

using clubwebsite - trouble with dataset dbnull

how to store multiple values in asp.net

displaying code in webpage

creating thumbs using ashx

inherits a class in usercontrol

setting access to a directory

getting started

inserting flash??

   
  Privacy | Contact Us
All Times Are GMT