After embedding some JavaScript files in a server control, everything works fine. However, when the server control is placed within an ajax UpdatePanel, it ceases to function after an async postback triggered within the updatepanel.
This is the code in the server control:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
ClientScriptManager clientScriptManager = Page.ClientScript;
const string DATE_TIME_PICKER_JS = "JQueryControls.Scripts.DateTimePicker.js";
clientScriptManager.RegisterClientScriptResource(typeof(DateTimePicker), DATE_TIME_PICKER_JS);
if (Ajax.IsControlInsideUpdatePanel(this) && Ajax.IsInAsyncPostBack(Page))
{
Ajax.RegisterClientScriptResource(Page, typeof(DateTimePicker), DATE_TIME_PICKER_JS);
}
}
The Ajax functionality can be found here.
This piece of code runs during the async postback:
public static void RegisterClientScriptResource(Page page, Type type, string resourceName) {
object scriptManager = FindScriptManager(page);
if (scriptManager != null) {
System.Type smClass = GetScriptManagerType(scriptManager);
if (smClass != null) {
Object[] args = new Object[] { page, type, resourceName };
smClass.InvokeMember("RegisterClientScriptResource",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.InvokeMethod,
null, null, args);
}
}
}
Is there any solution to make this work inside an UpdatePanel?