ServerSideCallBack and Dynamic Javascript

9 posts, 0 answers
  1. Paul Fleming
    Paul Fleming avatar
    6 posts
    Member since:
    Feb 2010

    Posted 24 Feb 2010 Link to this post

    Hi,

    On the expand event (callback) I generate some dynamic javascript that needs executing once the callback is complete. I've tried using Page.ClientScript.RegisterClientScript(...). I also tried ScriptManager.RegisterDataItem(...) to set the JS string to a textbox (which could then be picked up on callback completion). Neither of these worked. The latter complained that it can only be used when ScriptManager.IsInAsyncPostBack == true (which it isn't). I expected to see something similar to that on the RadAjaxManager (ResponseScripts). Am I missing something obvious? Please help.

    Thanks,
    Paul
  2. Yana
    Admin
    Yana avatar
    4850 posts

    Posted 24 Feb 2010 Link to this post

    Hi Paul,

    Why don't you try OnClientNodePopulated event of the treeview - it fires after the nodes are loaded.

    Best wishes,
    Yana
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Paul Fleming
    Paul Fleming avatar
    6 posts
    Member since:
    Feb 2010

    Posted 24 Feb 2010 Link to this post

    Hi Yana,

    I'm producing dynamic javascript inside the server side OnNodeExpand event. I need to get this script back to the client somehow. If I could add it to a hidden text field, it could be picked up in the OnClientNodePopulated event. My problem is that I can't get it back to the client.

    Thanks,
    Paul
  4. Yana
    Admin
    Yana avatar
    4850 posts

    Posted 26 Feb 2010 Link to this post

    Hello Paul,

    I am sorry I didn't explain more clearly.

    When you use ServerSideCallBack ExpandMode, the treeview makes an asynchronous request to the server, so in the NodeExpand event you cannot update the other controls on the page. I suggest you use ServerSide ExpandMode and wrap the whole treeview with RadAjaxPanel in order to preserve the client experience.

    The javascript  then can be executed like this:

    string scriptstring = "alert('test test');";
    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", scriptstring, true);

    All the best,
    Yana
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Paul Fleming
    Paul Fleming avatar
    6 posts
    Member since:
    Feb 2010

    Posted 26 Feb 2010 Link to this post

    Hi Yana,

    Thanks for you suggestion but I've found an alternative. I've inserted the dynamic JavaScript into the node's Category field. This is then retrieved on the client.

    Thanks for you help,
    Paul.
  6. Robert
    Robert avatar
    253 posts
    Member since:
    Aug 2007

    Posted 19 Jan 2011 Link to this post

    Dear Yana & Paul:

    I have a problem that I believe is similar to the one here.  Note: I have the latest version of the Rad Controls installed [2010.3.1215.35].

    In my project I have a Web Content form that has a RadTreeView in it.  Nodes are populated on demand and ExpandMode of each new node is set to ServerSideCallBack.  I don't really think I can change that now, as is explained here.

    In some unique circumstances, trying to expand a particular upper-level node reveals that it has no child nodes.  In the rare circumstances when this occurs I would very much like to show the user a message explaining why.  I thought I could just call the standard Javascript Alert box but when I did nothing happened, for reasons that I believe are the same as what Paul experienced.

    Now that it's almost a year later, might there be an easy way to do this?  And once again, I don't want to change from using ServerSideCallBack.  Finally, it doesn't necessarily have to be a Javascript Alert box, though that would be preferable.

    Sincerely,

    Robert W.
  7. Robert
    Robert avatar
    253 posts
    Member since:
    Aug 2007

    Posted 19 Jan 2011 Link to this post

    Yana & Paul:

    I thought more about what you two were saying and did this:

    In the RadTreeView layout code I added this local event handler definition:  OnClientNodePopulated="treeViewMain_ClientNodePopulated"

    Here's the little test function I created:

        function treeViewMain_ClientNodePopulated(sender, e) {
          var node = e.get_node();
          var msg = node.get_attributes().getAttribute("msg");
          debugger
        }

    Then in the server-side code, rather than calling my standardized method which inserts the necessary Javascript to show an Alert box, instead I added this:     nodeParent.Attributes.Add("msg", "test-test");

    Unfortunately, when I ran it, it didn't work.  The server-side code did run first and then the client-side code ran afterwards but the attribute value never got updated locally.  Following Paul's earlier post, I tried updating the "Category" property but no luck there either.

    So I *think* I'm close to a solution but sure would appreciate any help you could offer!!

    Robert
  8. Yana
    Admin
    Yana avatar
    4850 posts

    Posted 21 Jan 2011 Link to this post

    Hi Robert,

    The reason for this is the same - you cannot update even the parent node when ExpandMode is ServerSideCallBack - you can only add nodes to it.

    I suggest a different approach - you can still add a node with a different style in order to make it look as a message. I've attached a simple page to demonstrate the approach. Please download it and give it a try.

    Regards,
    Yana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  9. Robert
    Robert avatar
    253 posts
    Member since:
    Aug 2007

    Posted 21 Jan 2011 Link to this post

    Yana,

    Thank you for this.  Not precisely what I had in mind but an interesting solution nonetheless.

    I've now implemented it and the end effect is much better than I originally thought!  I have a tip for any future developers using the same technique:

    The horizontal space you have to write your "message" may likely be quite small.  But remember that you can have multiline tooltips!  Line breaks are effected with this character combination:  \r\n

    Robert
Back to Top