[DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), DefaultProperty("Text"), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class Script : Control
    {
        public string Type
        {
            get;
            set;
        }

        public string Src
        {
            get;
            set;
        }

        protected override void AddParsedSubObject(object obj)
        {
            if (!(obj is Script))
            {
                throw new HttpException(string.Format("Script cannot Have Children Of Type {0}.", obj.GetType().Name.ToString(CultureInfo.InvariantCulture)));
            }
            this.Type = ((Script)obj).Type;
            this.Src = ((Script)obj).Src;
        }

        protected override ControlCollection CreateControlCollection()
        {
            return new EmptyControlCollection(this);
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public override void Focus()
        {
            throw new NotSupportedException(string.Format("NoFocusSupport of type {0}.", base.GetType().Name));
        }

        protected override void Render(HtmlTextWriter writer)
        {
            string url = string.Empty;
            try
            {
                url = this.Page.ResolveUrl(this.Src??string.Empty);
            }
            catch (Exception) { }

            string text = string.Format("<script type=\"{0}\" src=\"{1}\"></script>", this.Type ?? string.Empty, url);
            writer.Write(text);
        }
    }

 

在aspx页面中的使用方法:
<%@ Register Assembly="ContentManagement.Entity" Namespace="ContentManagement.Entity.Aspx" tagprefix="aspx" %>

<aspx:Script runat="server" Type="text/javascript" Src="~/Scripts/jquery-1.4.2.min.js"></aspx:Script>
<aspx:Script runat="server" Type="text/javascript" Src="~/Scripts/jquery.validate.js"></aspx:Script>
<aspx:Script runat="server" Type="text/javascript" Src="~/Scripts/jquery.boxy.js"></aspx:Script>

 

 

此乃照猫画虎,通过反编译Litral控件写出来的,不对之处还请指正。

相关文章:

  • 2021-10-16
  • 2021-10-19
  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
猜你喜欢
  • 2021-05-24
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
  • 2022-01-05
  • 2022-03-06
  • 2022-12-23
相关资源
相似解决方案