Force postback from Treeview leaf node

Discussion in 'ASP .Net Web Controls' started by Bret, Jun 15, 2005.

  1. Bret

    Bret Guest

    Using the MS IE WebControls Treeview, I am displaying a series of
    hierarchical links (using client side <a> tags in the node text) for a user
    to click on to branch elsewhere.

    When they return to the page in question, I want to "remember" their last
    arrangement -- which node(s) were expanded (there are four levels here),
    which were not, etc.

    Setting the treeview to autopostback mode is a total non-starter; makes it
    unusable, so I'm trying variations involving forcing a postback when they
    click on a link. The pieces all work separately, but I can't get the postback
    to happen regularly. Here's the basic setup at present:

    On MyPage.aspx, I define the function that will actually request the
    postback:
    ....
    <script language="javascript">
    function poster(linkClicked)
    {
    window.execScript("__doPostBack('" + linkClicked + "', '');", "JavaScript");
    return true;
    }
    </script>
    ....

    (And lower in the page there is a linkbutton to ensure that the __doPostBack
    function is indeed generated.)

    Then the links are generated in the codebehind on pageload and look like
    this:
    ....
    <A id="leaf123" onclick="poster(this.id);return true;"
    href="pagetogoto.aspx">
    <A id="leaf124" onclick="poster(this.id);return true;"
    href="pagetogoto.aspx">
    ....

    Finally, in the codebehind for the page, I capture the postback in the
    page_load event and do the following:

    If Page.IsPostBack Then
    Session("ExpandedNodes") = SaveNodes(tvProc.Nodes)
    ....

    where SaveNodes is a recursive function that returns the expanded nodes in a
    manageable string. If the page is not a postback, I read that string back out
    of the session variable and expand the relevant nodes. (And I'll be happy to
    post the server side code details if I can get this working, but they're not
    the problem.)

    OK, deep breath. The above does not work as-is -- the postback just doesn't
    occur, but when I insert alert statements in the javascript function
    (poster), it DOES work.

    What am I doing wrong? I've experimented with delays in the javascript
    function, but no luck so far, and that just seems like a brutal hack (I know,
    like the rest of this isn't...), but I'm willing to give anything a go.

    Your help/feedback/alternate suggestions would be welcomed.
     
    Bret, Jun 15, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,674
  2. Alexandre Jaquet

    [JTree] Adding a leaf to a node

    Alexandre Jaquet, Nov 8, 2003, in forum: Java
    Replies:
    0
    Views:
    630
    Alexandre Jaquet
    Nov 8, 2003
  3. mazdotnet
    Replies:
    1
    Views:
    7,723
    mazdotnet
    Aug 1, 2006
  4. William Main

    Fixed bug in IE Treeview Webcontrol when clicking on leaf node.

    William Main, Feb 1, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    289
    William Main
    Feb 1, 2005
  5. Replies:
    0
    Views:
    402
Loading...

Share This Page