GetScriptReferences不会被调用 [英] GetScriptReferences does not get called

查看:119
本文介绍了GetScriptReferences不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了包含以下自定义控件:

I have written a Custom Control that contains the following:

[assembly: System.Web.UI.WebResource("InSysControls.AssignmentLists.AssignmentLists.js", "text/javascript")]
namespace InSysControls
{
    [ToolboxData("<{0}:AssignmentLists ID='AssignmentListsID' runat=\"server\"> </{0}:AssignmentLists>"), ParseChildren(true, "Items")]
    public class AssignmentLists : CompositeDataBoundControl, IScriptControl, INamingContainer
    {
    	#region IScriptControl Members

    	public IEnumerable<ScriptDescriptor> GetScriptDescriptors() {
    		ScriptControlDescriptor descriptor = new ScriptControlDescriptor(this.GetType().FullName, this.ClientID);
    		yield return descriptor;
    	}

    	public IEnumerable<ScriptReference> GetScriptReferences() {
    		yield return new ScriptReference("InSysControls.AssignmentLists.AssignmentLists.js", "InSysControls");
    	}

    	#endregion
    }
}

有谁知道的原因,既不GetScriptDescriptors或GetScriptReferences应该不会被调用?控制的其他部分工作得很好。

Does anyone know of a reason why neither GetScriptDescriptors or GetScriptReferences shouldn't get called? The other parts of the Control works just fine.

推荐答案

您需要注册控件作为ScriptControl的:

You need to register the control as a ScriptControl:

protected override void OnPreRender(EventArgs e)
{

    if (!this.DesignMode)
    {

        // Link the script up with the script manager
        ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
        if (scriptManager != null)
        {
            scriptManager.RegisterScriptControl(this);
        }

    }

    base.OnPreRender(e);

}

protected override void Render(HtmlTextWriter writer)
{
    if (!this.DesignMode)
    {
        ScriptManager.GetCurrent(this.Page).RegisterScriptDescriptors(this);
    }
    base.Render(writer);
}

这篇关于GetScriptReferences不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆