Example #1
0
        /// <summary>
        /// 将目前所有的脚本输出.
        /// </summary>
        /// <param name="key">脚本块的关键字.</param>
        public void WriteScript(string key = null)
        {
            if (this.code == string.Empty)
            {
                return;
            }

            ScriptHelper script = new ScriptHelper( );

            script.AppendCode(this.code);
            script.Build(new RazorScriptHolder(this.page), key);
            this.code = string.Empty;
        }
Example #2
0
        protected override void renderJQuery(JQueryUI jquery)
        {
            base.renderJQuery(jquery);

            // Generate scripts that are needed by WIDGET, each class that inherits from WidgetSetting can add needed scripts through method GetDependentScripts
            foreach (KeyValuePair <string, string> pair in this.uiSetting.GetDependentScripts( ))
            {
                string key = string.Format("__js{0}", pair.Key);

                if (!ScriptHelper.IsBuilt(new ASPXScriptHolder(this), key))
                {
                    ScriptHelper script = new ScriptHelper( );

                    script.AppendCode(pair.Value);

                    script.Build(new ASPXScriptHolder(this), key, ScriptBuildOption.Startup);
                }
            }

            for (int index = 0; index < this.uiSetting.Ajaxs.Length; index++)
            {
                AjaxSetting ajax = this.uiSetting.Ajaxs[index];

                if (!string.IsNullOrEmpty(ajax.ClientFunction))
                {
                    AjaxManager manager = this.NamingContainer.FindControl(ajax.AjaxManagerID) as AjaxManager;

                    if (null == manager)
                    {
                        throw new Exception(string.Format("没有找到 ID 为 {0} 的 AjaxManager 控件", ajax.AjaxManagerID));
                    }

                    foreach (AjaxSetting target in manager.AjaxList)
                    {
                        if (target.ClientFunction == ajax.ClientFunction)
                        {
                            if (ajax != target)
                            {
                                this.uiSetting.Ajaxs[index] = target;
                            }

                            break;
                        }
                    }
                }
            }

            // Append scripts that create the WIDGET, such as: __repeater( ... )
            jquery.Widget(this.uiSetting);
        }
Example #3
0
    protected void cmdOK4_Click(object sender, EventArgs e)
    {
        // 创建 ScriptHelper 对象
        ScriptHelper scriptHelper = new ScriptHelper();

        // 声明用于存储颜色值得数组
        ScriptHelper.RegisterArray(this, "colors", "10, 99, 10");

        // 添加可以得到不同颜色的函数
        scriptHelper.AppendCode("function GetNextColor(){colors[0]++;colors[1]--;colors[2]+=2;if(colors[0]>99){colors[0]=10;}if(colors[1]<10){colors[1]=99;}if(colors[2]>99){colors[2]=10;}return '#' + colors[0].toString() + colors[1].toString() + colors[2].toString(); }");

        // 设置时钟, 改变标签的颜色
        scriptHelper.SetInterval("function(){document.getElementById('span4').style.color = GetNextColor();}", 100);

        // 生成脚本
        scriptHelper.Build(this, option: ScriptBuildOption.Startup);
    }
Example #4
0
    protected void cmdRun2_Click(object sender, EventArgs e)
    {
        // 创建 ScriptHelper 对象
        ScriptHelper scriptHelper = new ScriptHelper();
        string       code         = this.txtCode2.Text;

        if (code == string.Empty)
        {
            // 没有脚本, 添加弹出消息框的脚本
            scriptHelper.Alert("'没有任何脚本'");
            scriptHelper.Build(this, option: ScriptBuildOption.Startup);
            return;
        }

        ScriptHelper.RegisterAttribute(this, this.lblCode2.ClientID, "innerText", code);
        scriptHelper.AppendCode(code);

        // 生成脚本到页面
        scriptHelper.Build(this, option: ScriptBuildOption.Startup);
    }
Example #5
0
        protected override void Render(HtmlTextWriter writer)
        {
            if (!this.Visible)
            {
                return;
            }

            if (this.isFaceless( ))
            {
                writer.Write("<span style=\"font-family: Verdana; background-color: #FFFFFF; font-size: 10pt;\"><strong>{0}:</strong> {1}</span>", "AjaxManager", this.ID);
            }

            if (this.DesignMode)
            {
                return;
            }

            ScriptHelper script = new ScriptHelper( );

            //!+ The following code is similar with AutocompleteSetting.Recombine, WidgetSetting.Recombine

            foreach (AjaxSetting ajax in this.ajaxs)
            {
                if (!string.IsNullOrEmpty(ajax.ClientFunction))
                {
                    string data;

                    if (string.IsNullOrEmpty(ajax.MethodName))
                    {
                        data = "data";
                    }
                    else
                    // According to the .NET version to determine the location of JSON
                    if (Environment.Version.Major <= 2 || (Environment.Version.Major == 3 && Environment.Version.Minor == 0))
                    {
                        data = "data";
                    }
                    else
                    {
                        data = "data.d";
                    }

                    if (!string.IsNullOrEmpty(ajax.Success))
                    {
                        ajax.Success = ajax.Success.Replace("-:data", data);
                    }

                    if (!string.IsNullOrEmpty(ajax.Complete))
                    {
                        ajax.Complete = ajax.Complete.Replace("-:data", data);
                    }

                    if (!string.IsNullOrEmpty(ajax.Error))
                    {
                        ajax.Error = ajax.Error.Replace("-:data", data);
                    }

                    JQuery jquery = JQueryUI.Create(ajax);

                    if (null != jquery)
                    {
                        script.AppendCode("function " + ajax.ClientFunction + "(" + ajax.ClientParameter + ") {" + jquery.Code + "}");
                    }
                }
            }

            script.Build(new ASPXScriptHolder(this), this.ClientID, ScriptBuildOption.Startup);
        }