• 自定义服务端Script控件支持javascript服务端路径?


    [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控件写出来的,不对之处还请指正。

  • 相关阅读:
    创建Hive/hbase相关联的表异常
    CDH5.2+CM5.2+impala2+Spark1.1 集群搭建基础环境准备
    【JavaWeb】(10)微信公众号开发进阶
    Ambari-stack介绍
    OSGi中的ServletContext
    笔试面试1 用C实现C库函数itoa, atoi
    SGU 114. Telecasting station 三分or找中位数
    face++实现人脸识别
    磁盘接口与磁盘扫描
    CSDN开源夏令营 百度数据可视化实践 ECharts(4)
  • 原文地址:https://www.cnblogs.com/nanfei/p/2931914.html
Copyright © 2020-2023  润新知