惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
Schneier on Security
Schneier on Security
V2EX - 技术
V2EX - 技术
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
O
OpenAI News
S
Security @ Cisco Blogs
Scott Helme
Scott Helme
Security Archives - TechRepublic
Security Archives - TechRepublic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
T
Threatpost
Hacker News: Ask HN
Hacker News: Ask HN
Microsoft Azure Blog
Microsoft Azure Blog
Know Your Adversary
Know Your Adversary
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
Forbes - Security
Forbes - Security
NISL@THU
NISL@THU
Security Latest
Security Latest
G
Google Developers Blog
D
Docker
T
Threat Research - Cisco Blogs
N
Netflix TechBlog - Medium
C
CERT Recently Published Vulnerability Notes
H
Help Net Security
B
Blog
Martin Fowler
Martin Fowler
N
News and Events Feed by Topic
Simon Willison's Weblog
Simon Willison's Weblog
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
Lohrmann on Cybersecurity
Y
Y Combinator Blog
PCI Perspectives
PCI Perspectives
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
Project Zero
Project Zero
爱范儿
爱范儿
Cisco Talos Blog
Cisco Talos Blog
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
人人都是产品经理
人人都是产品经理
V
Vulnerabilities – Threatpost
P
Proofpoint News Feed
Cyberwarzone
Cyberwarzone
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
N
News | PayPal Newsroom
Recorded Future
Recorded Future

博客园 - Love Fendi

性能优化系列---查询高cup的sql State模式学习 8.17--8.24积累 sql server 2005 analysis service step by step(三):创建父子维度 sql server 2005 analysis service step by step(二):创建时间维度 sql serve 2005 analysis service step by step(一):创建标准维度 算法练习五:求数组中第k大的数 算法练习四:求N!不溢出 算法练习三:奇偶分割 算法练习二:二分查找 数据库锁 算法练习一:最大公约数与最小公倍数 索引优化 生成验证码,同时异步获取加密后的验证码 一条语句删除表中某字段重复的数据 动态按需异步加载js文件 在Nhibernate中使用Json.net中出现Self referencing loop的错误的处理 JQuery学习笔记 c#委托事件 入门
自定义控件中与脚本资源集成的若干处理方式
Love Fendi · 2009-02-19 · via 博客园 - Love Fendi

包含以下几个知识:

1.服务器端向客户端添加脚本变量

2.服务器端向客户端添加数组

3.服务器端向客户端添加js脚本

public class ConfirmOnclick:Button
    {

        private string _scriptPath = "ControlClientScript/";

        public ConfirmOnclick()
            : base()
        {
 
        }
        public string Message
        {
            get
            {
                object o = ViewState["Message"];
                if (o == null)
                {
                    return string.Empty;
                }
                return o.ToString();
            }
            set
            {
                ViewState["Message"] = value;
            }
        }
        public String ScriptPath
        {
            get
            {
                return _scriptPath;
            }
            set
            {
                _scriptPath = value;
            }
        }
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            Attributes.Add("confirmationmessage", Message);
            base.AddAttributesToRender(writer);
        }

        protected override void OnPreRender(EventArgs e)
        {
            Page.RegisterClientScriptBlock("WebUIConfirmation", "<script language='javascript' src='" + ScriptPath + "JScript1.js" + "'></script>");
            Page.RegisterArrayDeclaration("Page_Confirmations", "'" + ClientID + "'");
            Page.RegisterStartupScript("WebUIConfirmation Startup", "<script language='javascript'>ConfirmOnload();</script>");
            base.OnPreRender(e);
        }

        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);
        }

    }

js文件

function ConfirmOnload() {
    var confirmButton;
    for (i = 0; i < Page_Confirmations.length; i++) {
        confirmButton = Page_Confirmations[i];
        if (typeof (confirmButton) == "string") {
            confirmButton = document.getElementById(confirmButton);
        }
    }
    ConfirmationHookupControl(confirmButton);
}

function ComrimationHookupControl(confirmButton) {
    var ev = confirmButton.onclick;
    if (typeof (ev) == "function") {
        ev = ev.toString();
        ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
    }
    else {
        ev = "";
    }
    var func = new Function("if ( !ConfirmationOnClick( this ) ){return false;} " + ev);
    confirmButton.onclick = func;
}

//弹出确认窗口
function ConfirmationOnClick(confirmButton) {
    return window.confirm(confirmButton.confirmationmessage);
}

4.动态添加css文件

 void RegisterClientCSSResource(string cssResource)
        {
            if (Page.Header != null)
            {
                string cssId = cssResource.Replace('.', '_');
                foreach (Control ctr in Page.Header.Controls)
                {
                    if (ctr.ID == cssId)
                        return;
                }
                string cssRef = Page.ClientScript.GetWebResourceUrl(this.GetType(), cssResource);
                HtmlLink link = new HtmlLink();
                link.Href = cssRef;
                link.Attributes.Add("type", "text/css");
                link.Attributes.Add("rel", "stylesheet");
                Page.Header.Controls.Add(link);
            }
            else
            {
                throw new NotSupportedException("页面没有Header对象");
            }
        }

5.引入js文件

Page.ClientScript.RegisterClientScriptResource(this.GetType(), "IntegrateWithJavascriptLibrary.jquery.js");