zoukankan      html  css  js  c++  java
  • 使用内嵌资源

    新建一个WebControls控件库,在其中添加一个alert.js文件,将其添加到./Resources文件夹下,选中该文件,右键→属性→生成操作→选择“嵌入的资源”。
    新建一个自定义控件,该控件继承自TextBox控件。代码如下:
     1using System;
     2using System.Collections.Generic;
     3using System.ComponentModel;
     4using System.Text;
     5using System.Web;
     6using System.Web.UI;
     7using System.Web.UI.WebControls;
     8
     9//引入该资源,注意,一次引用之后,在整个Web控件库中均可使用
    10//或者是在AssemblyInfo.cs中也可以添加对该文件的使用
    11//引用时资源时,其资源路径格式如下:命名空间.所在Folder.文件名
    12[assembly: WebResource("GridViewExtention.Resources.alert.js""text/javascript")]
    13namespace GridViewExtention
    14{
    15    [DefaultProperty("Text")]
    16    [ToolboxData("<{0}:TextBoxEx runat=server></{0}:TextBoxEx>")]
    17    public class TextBoxEx : TextBox
    18    {
    19        [Bindable(true)]
    20        [Category("Appearance")]
    21        [DefaultValue("")]
    22        [Localizable(true)]
    23        public override string Text
    24        {
    25            get
    26            {
    27                String s = (String)ViewState["Text"];
    28                return ((s == null? String.Empty : s);
    29            }

    30
    31            set
    32            {
    33                ViewState["Text"= value;
    34            }

    35        }

    36
    37        protected override void OnPreRender(EventArgs e)
    38        {
    39            //注册脚本
    40            Page.ClientScript.RegisterClientScriptResource(this.GetType(), "GridViewExtention.Resources.alert.js");
    41            base.OnPreRender(e);
    42        }

    43        protected override void Render(HtmlTextWriter writer)
    44        {
    45            //为该控件添加上客户端的onchange事件
    46            writer.AddAttribute("onchange""alertMsg(this.value);");
    47            base.Render(writer);
    48        }

    49
    50        protected override void RenderContents(HtmlTextWriter output)
    51        {
    52            output.Write(Text);
    53        }

    54    }

    55}

    56
    点个广告:
  • 相关阅读:
    浅析VO、DTO、DO、PO的概念、区别和用处
    serialVersionUID的作用
    Eclipse Debug提示source not found解决方案
    eclipse的块选择模式
    Java工程Properties配置文件注释中文,会自动转换为其他编码方式问题解决 中文乱码
    spring boot1.5以上版本@ConfigurationProperties取消location注解后的替代方案 cannot resolve method location
    c++11多线程
    多媒体指令(AVX加速数组求和)
    oracle数据库occi接口写入中文乱码解决方法
    c++得到窗口句柄
  • 原文地址:https://www.cnblogs.com/hanxianlong/p/934210.html
Copyright © 2011-2022 走看看