Register a Client Script Block inside an Ajax Panel or Ajaxified Control

I have written a few custom user controls that are now being used inside ajax panels or ajaxified controls using the RadAjaxManager. It is aways tricky getting the javascript to work correctly. I have recently discovered a method I had overlooked. With the introduction of Atlas and MS Ajax extensions many user controls now are loaded inside of an ajax postback. So how do you get the javascripts your control needs to work to register correctly. This code is an example to redirect to a url based on a selection in a dropdown list, of course you get a javascript error if the control is loaded in a Ajax Panel.

 
if (!Page.ClientScript.IsClientScriptBlockRegistered(GetType(), "GotoId")) 
    StringBuilder sb = new StringBuilder(); 
    sb.Append("function gotoId(listControl) "); 
    sb.Append("{ "); 
    sb.Append(" list = document.getElementById(listControl); "); 
    sb.Append(" loc = list.options[list.selectedIndex].value; "); 
    sb.Append(" if (loc) location.href = loc; "); 
    sb.Append("} "); 
 
    Page.ClientScript.RegisterClientScriptBlock(GetType(), "GotoId", sb.ToString(), true); 
DropDownNav.Attributes.Add("onchange"string.Format("return gotoId('{0}');", DropDownNav.ClientID)); 
  

So the solution is easy all you need to do is use the ScriptManager.RegisterClientScriptBlock instead of the Page.ClientScript.RegisterClientScriptBlock method.

 
    ScriptManager.RegisterClientScriptBlock(Page,GetType(), "GotoId", sb.ToString(), true); 
 

The controls I have written now work correctly when loaded in a ajaxified control.