脚本控件上没有调用GetScriptDescriptors

时间:2010-06-17 05:01:59

标签: asp.net asp.net-ajax

我正在为asp.net Ajax构建一个脚本控件,虽然我可以调用GetScriptReferences()函数,但我无法获得GetScriptDescriptors()

我尝试过ScriptControlScriptControlBaseIScriptControl。我正在使用页面脚本管理器注册控件,但我仍然无法调用该函数?

关于我可能遗漏的任何想法?

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];
    }
}

1 个答案:

答案 0 :(得分:0)

如果使用IScriptControl,则必须将其添加到渲染过程中:

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

如上所述:GetScriptReferences does not get called

RegisterScriptControl通知脚本管理器脚本,并调用GetScriptReferences。您需要调用RegisterScriptDescriptors来处理组件注册,并在客户端上调用后续的$create方法。