Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Force postback from Treeview leaf node

1 view
Skip to first unread message

Bret

unread,
Jun 15, 2005, 4:50:02 PM6/15/05
to
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.

0 new messages