views:

55

answers:

2

We're using an asp:TreeView configured with lazy loading. The callback method assigned for OnTreeNodePopulate throws an exception if the user has been logged out since the page was loaded. What we want to do is to direct the user to the login page.

First attempt was to catch the exception on the server and try Response.Redirect(...), but that doesn't work because you can't redirect within a callback.

I've tried various other approaches, including using ClientScript.RegisterStartupScript(...) but that doesn't seem to work for OnTreeNodePopulate.

If there was some way we could hook into the callback event handling on the client side then it would be easy, but the TreeView doesn't seem to offer anything here.

Suggestions?

A: 

OK, I have a workaround, though I'm still eager to hear other suggestions as this is total filth:

In my callback I catch the exception with the following block:

catch (Exception ex)
{
    if (IsAuthException(ex))
    {
        e.Node.ChildNodes.Add(new TreeNode(@"<script type=""text/javascript"">window.location.href = 'Default.aspx';</script>"));
    }
    else
    {
        throw;
    }
}

Fortunately the TreeView doesn't escape anything so the JS gets executed by the browser and directs the user to the login page.

Martin Hutchinson
Actually this doesn't work in IE -- it simply doesn't execute the JS. I've found something even more filthy that does work in both IE and FF though:e.Node.ChildNodes.Add(new TreeNode(@"<img width=""1"" height=""1"" onerror=""window.location.href = 'Default.aspx'"" src=""$""/>"));The image has an invalid URL so the onerror event is invoked. Nice.
Martin Hutchinson
A: 

hi i have same issue is I am generating the child node while clicking the parent node here i am using thickbox js so i parent node i have some link so it will show the modalpopup.

and the same link available on Child node this has been created through OnTreenodePopulate by setting OnPopulateDemand=True.

but if i click the link it will not show the modalpopup it will open on full page..?

when i check the page the thickbox,js was not called thats the problem..

how to solve the issue.

troy