zoukankan      html  css  js  c++  java
  • 自定义服务端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控件写出来的,不对之处还请指正。

  • 相关阅读:
    JVM(一)--Java内存区域
    leetcode33 搜索旋转排序数组
    二叉树的相关算法(一)
    分别求二叉树前、中、后序的第k个节点
    【蓝桥杯】历届试题 买不到的数目
    JAVA的JVM的内存可分为3个区:堆(heap)、栈(stack)和方法区(method)
    【蓝桥杯】核桃的数量
    Java内存分析之对象实例化操作初步分析
    【蓝桥杯】算法训练 K好数
    【蓝桥杯】基础练习试题
  • 原文地址:https://www.cnblogs.com/nanfei/p/2931914.html
Copyright © 2011-2022 走看看