IsClientScriptBlockRegistered() private method

private IsClientScriptBlockRegistered ( string key ) : bool
key string
return bool
        public static void RegisterClientCheckEvents(Page pg, string formID)
        {
            string strCol = GetCheckColScript();
            string strHead = GetCheckHeadScript();

            if(!pg.IsClientScriptBlockRegistered("clientScriptCheckAll"))
                pg.RegisterClientScriptBlock("clientScriptCheckAll", strHead.Replace("[frmID]",formID));
            if(!pg.IsClientScriptBlockRegistered("clientScriptCheckChanged"))
                pg.RegisterClientScriptBlock("clientScriptCheckChanged", strCol.Replace("[frmID]",formID));

            RegisterAttributes(pg);
        }
示例#2
0
    /// <summary>
    /// 功能:执行客户端一小块脚本语言。输出:无。
    /// </summary>
    /// <param name="page">脚本注册到在页</param>
    /// <param name="sb">注册的脚本内容,例:alert('dd');</param>
    /// <param name="strRegDirection">注册到页面上的位置,up是注册到:在Page对象的&lt;form runat='server'&gt;元素的开始标记后立即发出该脚本,默认为down</param>
    public void RegisterJs(System.Web.UI.Page page, StringBuilder sb, string strRegDirection)
    {
        string        strKey   = "";
        StringBuilder sbScript = new StringBuilder();
        int           i;

        //脚本块内容
        sbScript.Append("<script style='text/javascript'>\n");
        sbScript.Append(sb.ToString());
        sbScript.Append("</script>");

        //注册脚本块KEY
        strKey = System.DateTime.Now.ToString();
        //循环,直至找到某个没被注册过的Key
        for (i = 0; i < 100; i++)
        {
            if (!page.IsClientScriptBlockRegistered(strKey + i.ToString()))
            {
                break;
            }
        }

        if (strRegDirection == "up")
        {
            page.RegisterClientScriptBlock(strKey + i.ToString(), sbScript.ToString());
        }
        else //默认注册到页面下面
        {
            page.RegisterStartupScript(strKey + i.ToString(), sbScript.ToString());
        }
    }
    /// <summary>
    ///
    /// </summary>
    /// <param name="ScriptRegister">Javascript can thuc thi khi ham chay</param>
    /// <param name="page">Page thi hanh</param>
    static public void RunJavascript(System.Web.UI.Page page, string ScriptRegister)
    {
        string alertScript = "<script language=javascript>"
                             + ScriptRegister
                             + "</script>";

        if (!page.IsClientScriptBlockRegistered("alert"))
        {
            page.RegisterClientScriptBlock("alert", alertScript);
        }
    }
示例#4
0
        /// <summary>
        ///3 静态方法,关闭一个网页窗口。
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <example>
        /// JSUnit.CloseWindow(this);
        /// </example>
        public static void CloseWindow(System.Web.UI.Page page)
        {
            String scriptString = "<script language=JavaScript> ";

            scriptString += "window.close();";
            scriptString += "</script>";

            if (!page.IsClientScriptBlockRegistered("clientScript"))
            {
                page.RegisterClientScriptBlock("clientScript", scriptString);
            }
        }
示例#5
0
        /// <summary>
        ///3 静态方法,关闭一个模态网页窗口并刷新父窗口
        /// 前提条件是必须调用此类中的OpenModalDialog方法
        /// 在该方法中自动生成刷新方法才能实现父页面刷新。
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <example>
        /// JSUnit.CloseModalDialog(this);
        /// </example>
        public static void CloseModalDialog(System.Web.UI.Page page)
        {
            String scriptString = "<script language=JavaScript> ";

            scriptString += "var sData = dialogArguments;";
            scriptString += "sData.Refresh();";
            scriptString += "window.close();";
            scriptString += "</script>";

            if (!page.IsClientScriptBlockRegistered("clientScript"))
            {
                page.RegisterClientScriptBlock("clientScript", scriptString);
            }
        }
        /// <summary>
        /// Register the Client-Side script block in the ASPX page.
        /// </summary>
        protected void RegisterClientSideScriptBlock(System.Web.UI.Page page)
        {
            // Register the script block is not allready done.

            if (!page.IsClientScriptBlockRegistered(this.ScriptKey))
            {
                if ((this.ExternalScript == null || this.ExternalScript == string.Empty) && (this.ScriptDirectory == null || this.ScriptDirectory.TrimEnd() == string.Empty))
                {
#if (!FX1_1)
                    Page.ClientScript.RegisterClientScriptInclude(ScriptKey, Page.ClientScript.GetWebResourceUrl(this.GetType(), ResourceName));
#else
                    if (CLIENTSIDE_API == null)
                    {
                        CLIENTSIDE_API = EditorHelper.GetResource(this.ResourceName).ToString();
                    }

                    if (!CLIENTSIDE_API.StartsWith("<script"))
                    {
                        CLIENTSIDE_API = "<script language=\"javascript\">\n" + CLIENTSIDE_API;
                    }

                    CLIENTSIDE_API += "\n</script>\n";

                    page.RegisterClientScriptBlock(this.ScriptKey, CLIENTSIDE_API);
#endif
                }
                else
                {
                    if (this.ScriptDirectory.StartsWith("~"))
                    {
                        this.ScriptDirectory = this.ScriptDirectory.Replace("~", System.Web.HttpContext.Current.Request.ApplicationPath.TrimEnd('/'));
                    }
                    page.RegisterClientScriptBlock(this.ScriptKey, "<script language=\"javascript\" src=\"" + this.ScriptDirectory.TrimEnd('/') + "/" + (this.ExternalScript == string.Empty ? "ActiveInput.js" : this.ExternalScript) + "\"  type=\"text/javascript\"></SCRIPT>");
                }
            }


            if (!Page.IsClientScriptBlockRegistered(this.ScriptKey + "_startup"))
            {
                string startupString = string.Empty;
                startupString += "<script>\n";
                startupString += "// Test if the client script is present.\n";
                startupString += "try\n{\n";
                startupString += "AIP_testIfScriptPresent();\n";
                startupString += "}\n catch (e)\n {\n alert('Could not find script file. Please ensure that the Javascript files are deployed in the " + ((ScriptDirectory == string.Empty) ? string.Empty : " [" + ScriptDirectory + "] directory or change the") + "ScriptDirectory and/or ExternalScript properties to point to the directory where the files are.'); \n}\n";
                startupString += "</script>\n";

                page.RegisterClientScriptBlock(this.ScriptKey + "_startup", startupString);
            }
        }
示例#7
0
        /// <summary>
        /// 功能:在客户端注册一块脚本语言,在Page对象的 form runat= server 元素的开始标记后立即发出该脚本
        /// 输入:page   网页中的Page对象
        /// script 欲注册的JavaScript脚本,需要包括 script language=javascript 等标签
        /// 输出:无。
        /// </summary>
        /// <param name="page">网页中的Page对象(this)</param>
        /// <param name="script">欲注册的JavaScript脚本,需要包括 script language=javascript 等标签</param>
        public static void RegisterClientScriptBlock(System.Web.UI.Page page, string script)
        {
            string strKey;
            int    i;

            //注册脚本块的Key
            strKey = System.DateTime.Now.ToString();
            //循环,直至找到某个没被注册过的Key
            for (i = 0; i < 100; i++)
            {
                if (!page.IsClientScriptBlockRegistered(strKey + i.ToString()))
                {
                    break;
                }
            }
            page.RegisterClientScriptBlock(strKey + i.ToString(), script);
        }
示例#8
0
        public static void RegisterTitle(System.Web.UI.Page page, string title)
        {
            string titleScript = @"<script language=javascript>
									<!--
									document.title='"
                                 + title +
                                 @"';
									//-->
									</script>"                                    ;



            if (!page.IsClientScriptBlockRegistered("TitleKey"))
            {
                page.RegisterClientScriptBlock("TitleKey", titleScript);
            }
        }
示例#9
0
        /// <summary>
        ///5 静态方法,执行客户端一小块脚本语言,
        ///利用page的RegisterClientScriptBlock方法在客户端注册一段脚本,
        ///参数script无需包括html标记<script>、</script>。
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="script">javascript脚本</param>
        /// <example>
        /// JSUnit.ExecuteBlock(this,"alert("Hello");");
        /// </example>
        public static void ExecuteBlock(System.Web.UI.Page page, string script)
        {
            if (script != null)
            {
                String scriptString = "<script language=JavaScript> ";
                scriptString += script;
                scriptString += "</script>";

                if (!page.IsClientScriptBlockRegistered("clientScript"))
                {
                    page.RegisterClientScriptBlock("clientScript", scriptString);
                }
            }
            else
            {
                Alert(page, "JavaScript脚本不能为空!");
            }
        }
示例#10
0
        /// <summary>
        /// 指定控件获得焦点
        /// </summary>
        /// <param name="str_Ctl_Name">str_Ctl_Name是要获得焦点的控件的ID</param>
        /// <param name="page"></param>
        //public static void FocusNow(string str_Ctl_Name,Page page)
        //{
        //    page.RegisterStartupScript("","<script>document.forms(0)."+str_Ctl_Name+".focus(); document.forms(0)."+str_Ctl_Name+".select();</script>");
        //}


        #region 弹出信息窗体
        /// <summary>
        /// 1.静态方法,弹出信息窗体
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="description">信息内容</param>
        /// <example>
        /// JSUnit.Alert(this,"NiHao!");
        /// </example>
        public static void Alert(System.Web.UI.Page page, string description)
        {
            if (description != null)
            {
                String scriptString = "<script language=JavaScript> ";
                scriptString += "alert('" + description + "');";
                scriptString += "</script>";

                if (!page.IsClientScriptBlockRegistered("clientScript"))
                {
                    page.RegisterClientScriptBlock("clientScript", scriptString);
                }
            }
            else
            {
                Alert(page, "描述信息为空!");
            }
        }
示例#11
0
        // public static bool DeleteConfirm

        /// <summary>
        ///16 静态方法,在客户端注册一块脚本语言,
        ///在Page对象的form runat= server元素的开始标记之后立即发出该脚本。
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="script">JavaScript脚本</param>
        /// <example>
        /// JSUnit.RegisterClientScriptBlock(this,"alert("Hello!")");
        /// </example>
        public static void RegisterClientScriptBlock(System.Web.UI.Page page, string script)
        {
            if (script != null)
            {
                string str = "<script language='javascript'>"
                             + script
                             + "</script>";

                if (!page.IsClientScriptBlockRegistered("RegisterClientScriptBlock"))
                {
                    page.RegisterClientScriptBlock("RegisterClientScriptBlock", str);
                }
            }
            else
            {
                Alert(page, "JavaScript脚本不能为空!");
            }
        }
示例#12
0
        /// <summary>
        ///11 静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等)。
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="URL">页面名称</param>
        /// <param name="Width">宽度</param>
        /// <param name="Height">高度</param>
        /// <param name="Left">左边距</param>
        /// <param name="Top">上边距</param>
        /// <example>
        /// JSUnit.OpenIEWindow(page,"weihu.aspx",700,350,10,20);
        /// </example>
        public static void OpenIEWindow(System.Web.UI.Page page, string URL, int Width, int Height, int Left, int Top)
        {
            if (URL != null)
            {
                if (Width == 0 || Height == 0)
                {
                    Alert(page, "页面宽度和高度不能为零!");
                    return;
                }
                string str = "<script language='javascript'>"
                             + "window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + Width + ",height=" + Height + ",left=" + Left + ",top=" + Top + "');"
                             + "</script>";

                if (!page.IsClientScriptBlockRegistered("clientScript"))
                {
                    page.RegisterClientScriptBlock("clientScript", str);
                }
            }
            else
            {
                Alert(page, "页面地址不能为空!");
            }
        }
示例#13
0
        /// <summary>
        ///13	静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等),在屏幕的最右边,上下位置在中间。
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="URL">页面名称</param>
        /// <param name="Width">宽度</param>
        /// <param name="Height">高度</param>
        /// <example>
        /// JSUnit.OpenIEWindowRight(page,"weihu.aspx",700,350);
        /// </example>
        public static void OpenIEWindowRight(System.Web.UI.Page page, string URL, int Width, int Height)
        {
            if (URL != null)
            {
                if (Width == 0 || Height == 0)
                {
                    Alert(page, "页面宽度和高度不能为零!");
                    return;
                }
                string str = "<script language='javascript'>"
                             + "newwindow=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height + "');"
                             + "newwindow.moveTo(screen.width-" + Width + ",(screen.height-" + Height + ")/2);"
                             + "</script>";

                if (!page.IsClientScriptBlockRegistered("clientScript"))
                {
                    page.RegisterClientScriptBlock("clientScript", str);
                }
            }
            else
            {
                Alert(page, "页面地址不能为空!");
            }
        }
示例#14
0
文件: PageCas.cs 项目: nobled/mono
		public void Methods_Deny_Unrestricted ()
		{
			Page p = new Page ();
			p.DesignerInitialize ();
			Assert.IsNotNull (p.GetPostBackClientEvent (control, "mono"), "GetPostBackClientEvent");
			Assert.IsNotNull (p.GetPostBackClientHyperlink (control, "mono"), "GetPostBackClientHyperlink");
			Assert.IsNotNull (p.GetPostBackEventReference (control), "GetPostBackEventReference(control)");
			Assert.IsNotNull (p.GetPostBackEventReference (control, "mono"), "GetPostBackEventReference(control,string)");
			Assert.AreEqual (0, p.GetTypeHashCode (), "GetTypeHashCode");
			Assert.IsFalse (p.IsClientScriptBlockRegistered ("mono"), "IsClientScriptBlockRegistered");
			Assert.IsFalse (p.IsStartupScriptRegistered ("mono"), "IsStartupScriptRegistered");
			p.RegisterArrayDeclaration ("arrayname", "value");
			p.RegisterClientScriptBlock ("key", "script");
			p.RegisterHiddenField ("name", "hidden");
			p.RegisterOnSubmitStatement ("key", "script");
			p.RegisterRequiresPostBack (new HtmlTextArea ());
			p.RegisterRequiresRaiseEvent (new HtmlAnchor ());
			p.RegisterStartupScript ("key", "script");
			p.Validate ();
			p.VerifyRenderingInServerForm (control);
#if NET_2_0
			p.Controls.Add (control);
			Assert.IsNotNull (p.FindControl ("mono"), "FindControl");
			p.RegisterRequiresControlState (control);
			Assert.IsTrue (p.RequiresControlState (control), "RequiresControlState");
			p.UnregisterRequiresControlState (control);
			Assert.IsNotNull (p.GetValidators (String.Empty), "GetValidators");
			p.Validate (String.Empty);
#endif
		}