RegisterStartupScript() private method

private RegisterStartupScript ( string key, string script ) : void
key string
script string
return void
Example #1
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());
        }
    }
Example #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代码写到页面中去
        }
    }
Example #3
0
    /// <summary>
    /// 带回传函数的添加编辑删除提示
    /// </summary>
    /// <param name="msgtitle">提示文字</param>
    /// <param name="url">返回地址</param>
    /// <param name="msgcss">CSS样式</param>
    /// <param name="callback">JS回调函数</param>
    public void JscriptMsg(System.Web.UI.Page page, string msgtitle, string url, string msgcss, string callback)
    {
        string msbox = "jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\", " + callback + ")";

        page.RegisterStartupScript("message", "<script language='javascript'>" + msbox + "</script>");
        //ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox, true);
    }
Example #4
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, "页面地址不能为空!");
            }
        }
Example #5
0
 public void MSGBOX(String msg, System.Web.UI.Page pg)
 {
     msg = msg.Replace("'", "\\\'");
     msg = msg.Replace("\n", "\\\n");
     msg = msg.Replace("\r", "\\\r");
     msg = @"<script>alert('" + msg + "');</script>";
     pg.RegisterStartupScript(@"Startup", msg);
 }
Example #6
0
 public static void ShowAndRedirectDome(Page page, string msg, string url)
 {
     StringBuilder builder = new StringBuilder();
     builder.Append("<script language='javascript' defer>");
     builder.AppendFormat("alert('{0}');", msg);
     builder.AppendFormat("parent.location.href='{0}'", url);
     builder.Append("</script>");
     page.RegisterStartupScript("message", builder.ToString());
 }
Example #7
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);
        }
    }
Example #8
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);
    }
Example #9
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);
    }
Example #10
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);
        }
    }
Example #11
0
        /// <summary>
        /// 显示消息提示对话框,并进行页面跳转
        /// </summary>
        /// <param name="page">当前页面指针,一般为this</param>
        /// <param name="msg">提示信息</param>
        /// <param name="url">跳转的目标URL</param>
        public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url)
        {
            StringBuilder Builder = new StringBuilder();

            Builder.Append("<script language='javascript' defer>");
            Builder.AppendFormat("alert('{0}');", msg);
            Builder.AppendFormat("top.location.href='{0}'", url);
            Builder.Append("</script>");
            page.RegisterStartupScript("message", Builder.ToString());
        }
Example #12
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);
    }
        /// <summary>
        /// Registers the API script block.
        /// </summary>
        /// <param name="page">The page.</param>
        public virtual void RegisterAPIScriptBlock(System.Web.UI.Page page)
        {
            // Register the script block is not allready done.

            if (!Page.IsClientScriptBlockRegistered(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(), "ActiveUp.WebControls._resources.ActiveTree.js"));
#else
                    if (CLIENTSIDE_API == null || CLIENTSIDE_API == string.Empty)
                    {
                        CLIENTSIDE_API = EditorHelper.GetResource("ActiveUp.WebControls._resources.ActiveTree.js");
                    }

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

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

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

            string startupString = "<script language='javascript'>\n";
            startupString += "// Test if the client script is present.\n";
            startupString += "try\n{\n";
            startupString += "ATV_testIfScriptPresent();\n";
            //startupString += "}\ncatch (e) \n{\nalert('Could not find external script file. Please Check the documentation.');\n}\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 += "var atv_" + this.ClientID + "_de = '" + Utils.ConvertToImageDir(this.ImagesDirectory, this.Icons.Default, "folder.gif", this.Page, this.GetType()) + "';\n";
            startupString += "var atv_" + this.ClientID + "_ex = '" + Utils.ConvertToImageDir(this.ImagesDirectory, this.Icons.Expanded, "minus.gif", this.Page, this.GetType()) + "';\n";
            startupString += "var atv_" + this.ClientID + "_co = '" + Utils.ConvertToImageDir(this.ImagesDirectory, this.Icons.Collapsed, "plus.gif", this.Page, this.GetType()) + "';\n";
            startupString += "var atv_" + this.ClientID + "_path = '" + Path + "';\n";
            startupString += "</script>\n";

            page.RegisterStartupScript("ActiveTree_Startup_" + this.ClientID, startupString);
        }
Example #14
0
        public static void ShowAlert(string Message)
        {
            string strBuilder = "<script type='text/javascript'>alert('";

            strBuilder += Message;
            strBuilder += "')</script>";
            //return strBuilder;

            System.Web.UI.Page page = HttpContext.Current.Handler as System.Web.UI.Page;

            if (page != null)
            {
                page.RegisterStartupScript("runtime", strBuilder);
            }
        }
Example #15
0
        public static void RunStartUpScript(string script)
        {
            string strBuilder = "<script type='text/javascript'>";

            strBuilder += script;
            strBuilder += "</script>";
            //return strBuilder;

            System.Web.UI.Page page = HttpContext.Current.Handler as System.Web.UI.Page;

            if (page != null)
            {
                page.RegisterStartupScript("runtime", strBuilder);
            }
        }
Example #16
0
        /// <summary>
        /// 提示信息
        /// </summary>
        /// <param name="page">指定页</param>
        /// <param name="_Msg">消息</param>
        /// <param name="isTop">是否在头部/否则在尾部</param>
        public static void Alert(System.Web.UI.Page page, string _Msg, bool isTop)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<script language=\"javascript\"> \n");
            sb.Append("alert(\"" + _Msg.Trim() + "\"); \n");
            sb.Append("</script>\n");
            if (isTop)
            {
                page.RegisterClientScriptBlock("AlertTopJs", sb.ToString());
            }
            else
            {
                page.RegisterStartupScript("AlertBottomJs", sb.ToString());
            }
        }
Example #17
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);
        }
Example #18
0
        /// <summary>
        /// 向客户端发送函数KendoPostBack(eventTarget, eventArgument)
        /// 服务器端可接收__EVENTTARGET,__EVENTARGUMENT的值
        /// </summary>
        /// <param name="page">System.Web.UI.Page 一般为this</param>
        public static void JscriptSender(System.Web.UI.Page page)
        {
            page.RegisterHiddenField("__EVENTTARGET", "");
            page.RegisterHiddenField("__EVENTARGUMENT", "");
            string s = @"		
			<script language=Javascript>
				function KendoPostBack(eventTarget, eventArgument) 
				{
							var theform = document.forms[0];
							theform.__EVENTTARGET.value = eventTarget;
							theform.__EVENTARGUMENT.value = eventArgument;
							theform.submit();
						}
			</script>"            ;

            page.RegisterStartupScript("sds", s);
        }
Example #19
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脚本不能为空!");
            }
        }
Example #20
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脚本不能为空!");
            }
        }
Example #21
0
 public static void WriteTitle(Page pg,string title)
 {
     pg.RegisterStartupScript("title", "<script>document.title='�����ͨ���̼������޹�˾-" + title + "';</script>");
 }
Example #22
0
 public static void succeedTZShow(System.Web.UI.Page page, string msg, string tzpage)
 {
     page.RegisterStartupScript("message", "<script language='javascript' defer>alert('" + msg.ToString() + "');window.open( '" + tzpage.ToString() + "',target= 'main');</script>");
 }
Example #23
0
 /// <summary>
 /// 输出自定义脚本信息
 /// </summary>
 /// <param name="page">当前页面指针,一般为this</param>
 /// <param name="script">输出脚本</param>
 public static void ResponseScript(System.Web.UI.Page page, string script)
 {
     page.RegisterStartupScript("message", "<script language='javascript' defer>" + script + "</script>");
 }
Example #24
0
        /// <summary>
        /// 弹出提示信息
        /// </summary>
        /// <param name="key">key</param>
        /// <param name="message">提示信息</param>
        /// <param name="page">当前请求的page</param>
        public static void Alert(string key, string message, Page page)
        {
            string msg = string.Format("<script language=\"javascript\">alert(\"{0}\");</script>", message);

            page.RegisterStartupScript(key, msg);
        }
Example #25
0
 /// <summary>
 /// 显示消息提示对话框
 /// </summary>
 /// <param name="page">当前页面指针,一般为this</param>
 /// <param name="msg">提示信息</param>
 public static void  Show(System.Web.UI.Page page, string msg)
 {
     page.RegisterStartupScript("message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
 }
Example #26
0
 public static void ResponseScript(Page page, string script)
 {
     page.RegisterStartupScript("message", "<script language='javascript' defer>" + script + "</script>");
 }
Example #27
0
 public static void confirmShow(System.Web.UI.Page page, string msg)
 {
     page.RegisterStartupScript("message", "<script language='javascript' defer>win.confirmInfo('" + msg.ToString() + "',null,null,'提示');</script>");
 }
Example #28
0
    /// <summary>
    /// 获得焦点
    /// </summary>
    /// <param name="ctrl">控件名(this.TextBox)</param>
    /// <param name="page">this.page</param>
    public static void SetFocus(System.Web.UI.Control ctrl, System.Web.UI.Page page)
    {
        string s = "<SCRIPT language='javascript' defer>document.getElementById('" + ctrl.ID + "').focus() </SCRIPT>";

        page.RegisterStartupScript("focus", s);                                 //5+1+a+s+p+x
    }
Example #29
0
 public void javaScript(string alert, System.Web.UI.Page WebPage)
 {
     WebPage.RegisterStartupScript("script", "<script language=javascript>alert('" + alert + "');</script>");
 }
Example #30
0
    protected void CloseUploadProgress(System.Web.UI.Page page)
    {
        string scriptContent = "<script>document.getElementById('divBg11').style.display='none';document.getElementById('divProcessing11').style.display='none';</script>";

        page.RegisterStartupScript("errscript", scriptContent);
    }
Example #31
0
    protected void AlertInformation(System.Web.UI.Page page, string alertInformation)
    {
        string scriptContent = "<script>alert('" + alertInformation + "');</script>";

        page.RegisterStartupScript("errscript", scriptContent);
    }
Example #32
0
        /// <summary>
        /// Sets the focus to the control with the given name
        /// </summary>
        /// <param name="page">Page Control which hosts the control</param>
        /// <param name="formID">The ID of the html form that holds the control</param>
        /// <param name="controlID">The ID of the control that focus will be set to</param>
        public static void setFocus(Page page, string controlID)
        {
            string javascript = string.Format( @"
            <script language=""javascript"">

            var called = false;

            if(document.body.onfocus)
            orig_document_body_onfocus = document.body.onfocus;

            document.body.onfocus = document_body_onfocus;

            function setFocus()
            {{
            var control = document.getElementById(""{0}"");
            if(control)
            control.focus();
            }}

            function orig_document_body_onfocus(){{}}

            function document_body_onfocus ()
            {{
            if( !called )
            {{
            called = true;
            setFocus();
            }}

            orig_document_body_onfocus();
            }}

            if( window.__smartNav && window.__smartNav.restoreFocus)
            {{
            orig_window__smartNav_restoreFocus = window.__smartNav.restoreFocus;
            window.__smartNav.restoreFocus = window__smartNav_restoreFocus;
            }}

            function orig_window__smartNav_restoreFocus(){{}}

            function window__smartNav_restoreFocus()
            {{
            setFocus();
            orig_window__smartNav_restoreFocus
            }}

            </script>", controlID);

            page.RegisterStartupScript("focus", javascript);
        }
Example #33
0
 public static void Show(Page page, string msg)
 {
     page.RegisterStartupScript("message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
 }
Example #34
0
 public static void Show(Page page, string msg)
 {
     page.RegisterStartupScript("message", "<script language='javascript' defer>alert('" + msg.Replace("'", "¡¯").Replace("\r\n", "") + "');</script>");
 }
Example #35
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
		}
Example #36
0
 public static void Alert(System.Web.UI.Page page, string str)
 {
     page.RegisterStartupScript(new Random().Next().ToString(), string.Format("<script>window.parent.myclose(\"{0}\");</script>", str));
 }