IsStartupScriptRegistered() private method

private IsStartupScriptRegistered ( string key ) : bool
key string
return bool
Exemplo n.º 1
0
        /// <summary>
        ///8	静态方法,打开一个网页对话框,并生成刷新页面方法。
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="URL">页面名称</param>
        /// <param name="Width">宽度</param>
        /// <param name="Height">高度</param>
        /// <example>
        /// JSUnit.OpenModalDialog(page,"weihu.aspx",700,350);
        /// </example>
        public static void OpenModalDialog(System.Web.UI.Page page, string URL, int Width, int Height)
        {
            if (URL != null)
            {
                if (Width == 0 || Height == 0)
                {
                    Alert(page, "页面宽度和高度不能为零!");
                    return;
                }
                string scriptString = "<script language='javascript'>";
                scriptString += "function Refresh()";
                scriptString += "{";
                scriptString += "	window.location.href= window.location.href;";
                scriptString += "}";
                scriptString += "window.showModalDialog('" + URL + "',window,'dialogHeight:" + Height + "px;dialogWidth:" + Width + "px;center:Yes;help:No;scroll:No;resizable:No;status:No;')";
                scriptString += "</script>";

                if (!page.IsStartupScriptRegistered("Startup"))
                {
                    page.RegisterStartupScript("Startup", scriptString);
                }
            }
            else
            {
                Alert(page, "页面地址不能为空!");
            }
        }
Exemplo n.º 2
0
    public void SetFocus(System.Web.UI.Page page, String m_focusedControl)
    {
        //如果控件名称为空,则返回
        if (m_focusedControl == "")
        {
            return;
        }
        //添加脚本以声明函数
        StringBuilder sb = new StringBuilder("");

        sb.Append("<script language=javascript>");
        sb.Append("function ");
        sb.Append("setFocusFunctionName");
        sb.Append("(ctl) {");
        sb.Append("if(document.forms[0][ctl] != null) ");//如果不为空,则设置焦点,这里调用的Javascript里面的方法
        sb.Append(" document.forms[0][ctl].focus();");
        sb.Append("}");

        //添加脚本以调用函数
        sb.Append("setFocusFunctionName");
        sb.Append("('");
        sb.Append(m_focusedControl);
        sb.Append("');");
        sb.Append("</");
        sb.Append("script>");

        if (!page.IsStartupScriptRegistered("SetFocusScriptName"))
        {
            page.RegisterStartupScript("SetFocusScriptName", sb.ToString());//将这段javascript代码写到页面中去
        }
    }
Exemplo n.º 3
0
    public static void CreateMessageAlert(System.Web.UI.Page senderPage, string alertMsg, string alertKey)
    {
        string strScript = "<script language=JavaScript>alert('" + alertMsg + "')</script>";

        if (!(senderPage.IsStartupScriptRegistered(alertKey)))
        {
            senderPage.RegisterStartupScript(alertKey, strScript);
        }
    }
Exemplo n.º 4
0
    public static void SetFocus(System.Web.UI.Page page, System.Web.UI.Control ctrl)
    {
        string s = "<script language='javascript'>" +
                   "document.getElementById('" + ctrl.ID + "').focus() </script>";

        if (!page.IsStartupScriptRegistered("focus"))
        {
            page.RegisterStartupScript("focus", s);
        }
    }
Exemplo n.º 5
0
    /*=====================================================================================================*/

    public static bool CreateMessage(System.Web.UI.Page aspxPage, string strMessage)
    {
        string strScript = @"<script language=JavaScript>alert('" + strMessage + "'); self.close();</script>";

        if (!aspxPage.IsStartupScriptRegistered("strKey1"))
        {
            aspxPage.RegisterStartupScript("strKey1", strScript);
        }
        return(false);
    }
Exemplo n.º 6
0
    /*=====================================================================================================*/

    public static bool CreateMessageAlertToAWebPage(System.Web.UI.Page aspxPage, string strMessage, string pagename)
    {
        string strScript = @"<script language=JavaScript>alert('" + strMessage + "'); window.location.href('" + pagename + "')</script>";

        if (!aspxPage.IsStartupScriptRegistered("strKey1"))
        {
            aspxPage.RegisterStartupScript("strKey1", strScript);
        }
        return(false);
    }
Exemplo n.º 7
0
    /*=====================================================================================================*/

    public static bool CreateMessageAlertForAspxPage(System.Web.UI.Page aspxPage, string strMessage)
    {
        string strScript = "<script language=JavaScript>alert( \"" + strMessage + "\" )</script>";

        if (!aspxPage.IsStartupScriptRegistered("strKey1"))
        {
            aspxPage.RegisterStartupScript("strKey1", strScript);
        }
        return(false);
    }
Exemplo n.º 8
0
        /// <summary>
        /// 功能:在客户端注册一块脚本语言,在Page对象的 form 元素的结束标记之前发出该脚本
        /// 输入: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 RegisterStartupScript(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.IsStartupScriptRegistered(strKey + i.ToString()))
                {
                    break;
                }
            }
            page.RegisterStartupScript(strKey + i.ToString(), script);
        }
Exemplo n.º 9
0
        /// <summary>
        ///6 静态方法,执行客户端一小块脚本语言,
        ///利用page的RegisterStartupScript方法在客户端注册一段脚本,
        ///参数script无需包括html标记<script>、</script>。
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="script">JavaScript脚本</param>
        public static void ExecuteStartup(System.Web.UI.Page page, string script)
        {
            if (script != null)
            {
                String scriptString = "<script language=JavaScript> ";
                scriptString += script;
                scriptString += "</script>";

                if (!page.IsStartupScriptRegistered("ExecuteStartup"))
                {
                    page.RegisterStartupScript("ExecuteStartup", scriptString);
                }
            }
            else
            {
                Alert(page, "JavaScript脚本不能为空!");
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 15 静态方法,在客户端注册一块脚本语言,
        /// 在Page对象的form runat= server元素的结束标记之前发出该脚本。
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="script">JavaScript脚本</param>
        /// <example>
        /// JSUnit.RegisterStartupScript(this,"alert("Hello!")");
        /// </example>
        public static void RegisterStartupScript(System.Web.UI.Page page, string script)
        {
            if (script != null)
            {
                string scriptString = "<script language='javascript'>"
                                      + script
                                      + "</script>";

                if (!page.IsStartupScriptRegistered("RegisterStartupScript"))
                {
                    page.RegisterStartupScript("RegisterStartupScript", scriptString);
                }
            }
            else
            {
                Alert(page, "JavaScript脚本不能为空!");
            }
        }
Exemplo n.º 11
0
		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
		}