GetScriptDescriptors not being called on Script Control
I'm building a script control for asp.net Ajax, and while i can get the GetScriptReferences()
function to be called, i cannot get the GetScriptDescriptors()
.
I've tried deriving from ScriptControl
, Sc开发者_StackOverflow社区riptControlBase
, IScriptControl
. I'm registering the control with the pages script manager, but i still cannot get the function to be called?
Any ideas on what i might have missed?
public class FilterGroupingControl : CompositeControl, IScriptControl
{
public List<FilterGrouping> Groupings { get; set; }
public FilterGroupingControl()
{
this.Groupings = new List<FilterGrouping>();
}
protected override void OnPreRender(EventArgs e)
{
#region register control with script manager
ScriptManager scriptManager = ScriptManager.GetCurrent(Page);
if (scriptManager == null)
throw new InvalidOperationException("There must be a script manager on the page");
scriptManager.RegisterScriptControl(this);
#endregion
base.OnPreRender(e);
}
public IEnumerable<ScriptDescriptor> GetScriptDescriptors()
{
throw new InvalidOperationException();
ScriptControlDescriptor d = new ScriptControlDescriptor("Web.UI.Controls.FilterGroupingControl", this.ClientID);
d.AddProperty("Groupings", this.Groupings.ToArray());
return new ScriptDescriptor[] { d };
}
public IEnumerable<ScriptReference> GetScriptReferences()
{
// throw new InvalidOperationException();
return new ScriptReference[0];
}
}
if you use IScriptControl
, you must then add this to the render process:
if (!this.DesignMode)
{
ScriptManager.GetCurrent(this.Page).RegisterScriptDescriptors(this);
}
As mentioned here: GetScriptReferences does not get called
RegisterScriptControl
notifies the script manager of the scripts, and invokes GetScriptReferences. You need to call RegisterScriptDescriptors
to handle the component registration, and subsequent $create
method call on the client.
精彩评论