在web页面中使用 file.js 文件中的脚本和使用style 文件一样,要在业面中先引用,这个文件

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Drawing;
    using System.Drawing.Design;namespace ASM.Web.WebControl.OneClickButton
    {
        [DefaultProperty("Text")]
        [ToolboxData("<{0}:OneClickButton runat=server></{0}:OneClickButton>")]
        public class OneClickButton : Button
        {
            private string _ShowMsg;
            private string _Src;
            private int _Opacity;
            private Color _Color;        [Bindable(true), Category("Show Message"), DefaultValue(""), Description("Show message on the page")]
            public string ShowMessage
            {
                get
                {
                    return _ShowMsg;
                }            set
                {
                    _ShowMsg = value;
                }
            }        [Bindable(true), Category("Show Message"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor", typeof(UITypeEditor)), Description("Image URL")]
            public string IMGSrc
            {
                get
                {
                    return _Src;
                }            set
                {
                    _Src = value;
                }
            }
            [Bindable(true), Category("Show Message"), DefaultValue(""), TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter)), Description("Color")]
            public Color PageBackColor
            {
                get
                {
                    if (_Color == Color.Empty)
                    {
                        _Color = Color.White;
                    }  
                     return _Color;
                }            set
                {
                    if (value == Color.Empty)
                    {
                        value = Color.White;
                    }
                    _Color = value;            }
            }        [Bindable(true), Category("Show Message"), DefaultValue(""), Description("Opacity value between 0 ~ 100")]
            public int PageOpacity
            {
                get
                {
                    try
                    {
                        int.Parse(_Opacity.ToString());
                    }
                    catch
                    {
                        _Opacity = 50;
                    }
                    return _Opacity;
                }
                set
                {
                    if (value < 0 || value > 100)
                    {
                        value = 50;
                    }
                    _Opacity = value;
                }
            }        protected override void OnPreRender(System.EventArgs e)
            {
                string ImgUrl = "";
                if (_Src != string.Empty)
                {
                    if (_Src.StartsWith("~"))
                    {
                        ImgUrl = _Src.Remove(0, 2);
                    }
                    else
                    {
                        ImgUrl = _Src;
                    }
                }
                else
                {
                    ImgUrl = "";
                }
                string color = "";
                if (!_Color.IsEmpty)
                {
                    if (_Color.IsNamedColor == false)
                    {
                        color = "#" + _Color.Name.Remove(0, 2);
                    }
                    else
                    {
                        color = _Color.Name;
                    }
                }
                else
                {
                    color = Color.White.Name;
                }
                Page.ClientScript.RegisterStartupScript(typeof(Page), "script", "<script>function CreateDiv(){" +
                    "var div=document.createElement(\"<div id='div_show_d' style='position:absolute;visibility:visible;background:" + color + ";filter:alpha(opacity=" + _Opacity.ToString().Trim() + ");z-index:2;left:0;top:0;width:100%;height:100%;' onselectstart='return false' oncontextmenu='window.event.returnvalue=false'></div>\");" +
                    "document.body.appendChild(div);" +
                    "document.getElementById('div_show_d').innerHTML=\"<Table style='width:100%;height:100%;' oncontextmenu=return(false)><tr><td  align='center' valign='middle'><img id='img1111' runat='server' src='load.gif' /><br/>" + ShowMessage + "</td></tr></Table>\";}</script>" +//" + ImgUrl + "
                    "<script type=\"text/javascript\" language=\"javascript\" event=\"onclick\" for=\"" + base.ClientID + "\">" +
                    "CreateDiv();</script>");
            }
        }
    }
      

  2.   

    您的这个是用的script 连接串  但我的脚本比较大如果用连接串的话会带来很大的麻烦的
    所以我想直接吧JS文件嵌入到控件中去 但是总是无法执行脚本 正如我上面写的  不知道您是否能解决