GetScriptDescriptors not called in Script Control

I am creating a script control for asp.net Ajax, and while I can get the function GetScriptReferences()that I call, I cannot get GetScriptDescriptors().

I tried to get by ScriptControl, ScriptControlBase, IScriptControl. I am registering a control using the page manager script, but I still cannot get this 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];
    }
}
+3
source share
1 answer

if you use IScriptControl, you should add this to the rendering process:

if (!this.DesignMode)
    {
        ScriptManager.GetCurrent(this.Page).RegisterScriptDescriptors(this);
    }

As mentioned here: GetScriptReferences is not called

RegisterScriptControl script GetScriptReferences. RegisterScriptDescriptors $create .

0

Source: https://habr.com/ru/post/1750427/


All Articles