Event for client-side TreeView initialized?

3 posts, 1 answers
  1. Sebastian
    Sebastian avatar
    13 posts
    Member since:
    Feb 2009

    Posted 25 Jan 2010 Link to this post


    I currently have this problem: After a postback, I want to display/update additional information about the currently selected node.
    The problem is the order of the scripts that are generated. At server side I use this call to render the script that should be executed after the postback:

    ScriptManager.RegisterStartupScript(_updatePanel, _updatePanel.GetType(), "UpdateDetails""var treeView = $find('" + _navigationTree.ClientID + "'); UpdateDetailDisplay();"true); 

    On Client side, this script gets rendered and executed:

    var treeView = $find('ctl00_controlArea_ctl01_ctl04_ctl02'); 
    UpdateDetailDisplay(); // internally uses treeView.get_selectedNode(); to read data... 

    As you can see, the _preInitialize gets executed *AFTER* my script - which is - of course - totally wrong order. I need the treeview client side object initialized before my call gets executed, because the $find() call returns null in this case.

    How can I achieve this?

    Using setTimeout is no option. This would a) delay the user interface update and b) I still can't be sure that the TreeView object is fully initialized when the timeout triggers.

    Is there a event that is triggered after a postback where I can be sure that the treeview client side object is fully initialized?


  2. Answer
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Jan 2010 Link to this post

    Hi Sebastian,

    I guess you want to access the treeview client object in the evet handler after postback. If so you can try the following approach.

        protected void Button1_Click(object sender, EventArgs e) 
            string script = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(UpdateDetailDisplay);</script>"
            ClientScript.RegisterStartupScript(this.GetType(), "showWindow", script);   

       <script type="text/javascript"
            function UpdateDetailDisplay() { 
                treeView = $find('<%=RadTreeView1.ClientID %>'); 

  3. Sebastian
    Sebastian avatar
    13 posts
    Member since:
    Feb 2009

    Posted 25 Jan 2010 Link to this post

    That does the trick. The script is executed at a point where I have access to the TreeView client side object. Thank you.
Back to Top