3

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, ScriptControlBase, 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];
    }
}
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
mrwayne
  • 627
  • 6
  • 15
  • Script control should have worked because it does call the method in render, unless you override render and never call base.Render... – Brian Mains Feb 05 '12 at 01:06

1 Answers1

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.

Community
  • 1
  • 1
Brian Mains
  • 50,520
  • 35
  • 148
  • 257