This is a migrated thread and some comments may be shown as answers.

ServerSideCallBack and Dynamic Javascript

8 Answers 130 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Paul Fleming
Top achievements
Rank 1
Paul Fleming asked on 24 Feb 2010, 02:25 PM
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

8 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 24 Feb 2010, 02:28 PM
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.
0
Paul Fleming
Top achievements
Rank 1
answered on 24 Feb 2010, 02:49 PM
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
0
Yana
Telerik team
answered on 26 Feb 2010, 12:59 PM
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.
0
Paul Fleming
Top achievements
Rank 1
answered on 26 Feb 2010, 02:57 PM
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.
0
Robert
Top achievements
Rank 1
answered on 20 Jan 2011, 03:47 AM
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.
0
Robert
Top achievements
Rank 1
answered on 20 Jan 2011, 04:17 AM
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
0
Yana
Telerik team
answered on 21 Jan 2011, 04:32 PM
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.
0
Robert
Top achievements
Rank 1
answered on 22 Jan 2011, 04:00 AM
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
Tags
TreeView
Asked by
Paul Fleming
Top achievements
Rank 1
Answers by
Yana
Telerik team
Paul Fleming
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Share this question
or