views:

2752

answers:

3

I have a page with a dynamicly created javascript (the script is pretty static really, but the value of its variables are filled based on user input).

The result and the controls to take user input is inside an UpdatePanel which updates itself on certain user intputs. Some of these userinputs cause changes in the variables i spoke of earlier so i need to register a new javascript.

The problem ofcourse is that only the updatepanel gets updated and the scripts are registred outside the update panel so no new scripts are added.

What do you think would be best practice now? I could solve this by letting this script (and variables) live inside the updatepanel or i could make sure the page is fully reloaded when the need for posting a new javascript arises? The ScriptManager that i already have on the page might be able to help me with this...

So i'm looking for someone who either had similar problems and solved them in a nice way, or just someone with some bright ideas :)

+2  A: 

Have a look at ScriptManager.RegisterClientScriptBlock.

Crescent Fresh
It won't solve the problem on its own atleast :)
Per Hornshøj-Schierbeck
A: 

Why not just put the variables inside the update panel, or have the JavaScript get the values through the DOM?

Mark Brackett
yes, putting the variables(or full script) was one of my proposals but thanks for the point - the javascript can't get it through the dom since the data is not part of the dom (it's actually data used to update the dom with as the user inputs stuff)
Per Hornshøj-Schierbeck
You could add the data to the DOM, or screw the UpdatePanel and just make an AJAX/SciptMethod call to get the data.
Mark Brackett
+1  A: 

I've had better luck with ScriptManager.RegisterStartupScript than I did with ScriptManager.RegisterClientScriptBlock. You might give that a shot.

Jason