Example #1
0
File: Js.cs Project: pczy/Pub.Class
 /// <summary>
 /// 运行JS代码
 /// </summary>
 /// <param name="Page">指定Page</param>
 /// <param name="strCode">要注册的代码</param>
 /// <param name="isTop">是否在头部/否则在尾部</param>
 /// <param name="IDStr">Key</param>
 public static void Run(System.Web.UI.Page Page, string strCode, bool isTop, string IDStr) {
     StringBuilder sb = new StringBuilder();
     sb.Append("<script language=\"javascript\">\n");
     sb.Append(strCode.Trim());
     sb.Append("\n</script>\n");
     if (isTop) Page.RegisterClientScriptBlock(IDStr, sb.ToString()); else Page.RegisterStartupScript(IDStr, sb.ToString());
 }
        /// <summary>
        /// Add a Session-Lifeguard for a defined time. This Lifeguard is to prevent the connection to run into a  session 
        /// timeout
        /// </summary>
        /// <param name="timeout">Lifeguard time (minimal elapse to timeout) in Minutes, -1 = infinite, 0 = no Lifeguard
        /// </param>
        /// <param name="currentPage">The current Page Object</param>
        public static void AddLifeguard(int timeout, System.Web.UI.Page currentPage)
        {
            int interval = System.Web.HttpContext.Current.Session.Timeout;   // Minutes.

            // Prepare the script-code.
            string scriptCode = "";
            if (-1 == timeout || (timeout > interval))
            {
                scriptCode += "<script language=\"JavaScript\" src=\"CommonUtilities.js\"></script>";
                int reconnectCount = 0;
                if (-1 != timeout)
                {
                    timeout *= 60; // Seconds.
                    interval *= 60; // Seconds.

                    // Calculate the interval and the number of reconnects to keep the session alive until the defined timeout.
                    timeout -= interval;
                    reconnectCount = (int)Math.Ceiling((double)timeout / (interval - 45));
                    interval = timeout / reconnectCount;
                }
                else
                {
                    // Infinite Session-Lifeguard
                    interval = interval * 60 - 45;
                    reconnectCount = 0;
                }
                scriptCode += string.Format("<script language=\"JavaScript\">AddLifeguard({0}, {1});</script>",
                  interval * 1000, reconnectCount);
            }

            currentPage.RegisterClientScriptBlock("AddLifeguard", scriptCode);
        }
    /// <summary>
    /// Focuses the page on a certain control. Got code from http://www.codeproject.com/Articles/9731/How-to-scroll-an-ASP-NET-control-into-view-after-p
    /// </summary>
    /// <param name="ClientID">The ID given to the control</param>
    /// <param name="page">The page the control is on.</param>
    /// Andrew Heim  - 12/3/12
    public static void FocusControlOnPageLoad(string ClientID,
                                            System.Web.UI.Page page)
    {
        page.RegisterClientScriptBlock("CtrlFocus",

            @"<script>

          function ScrollView()

          {
         var el = document.getElementById('" + ClientID + @"')
         if (el != null)
         {
            el.scrollIntoView();
            el.focus();
         }
          }

          window.onload = ScrollView;

          </script>");
    }
		public static void RegisterItemControlDivsForPage (System.Web.UI.Page thePage){			
			if (!thePage.IsClientScriptBlockRegistered("divscontrol")) {
				thePage.RegisterClientScriptBlock("divscontrol",LibraryScript("ExpandingDivs.js"));
			}
		}
 /// <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();
     //ѭ����ֱ���ҵ�ij��û��ע�����Key
     for (i = 0; i < 100; i++)
         if (!page.IsClientScriptBlockRegistered(strKey + i.ToString()))
             break;
     page.RegisterClientScriptBlock(strKey + i.ToString(), script);
 }
Example #6
0
File: Js.cs Project: pczy/Pub.Class
 /// <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 #7
0
File: Js.cs Project: pczy/Pub.Class
 /// <summary>
 /// 提示信息
 /// </summary>
 /// <param name="Page">指定页</param>
 /// <param name="msg">消息</param>
 public static void Alert(System.Web.UI.Page Page, string msg) {
     StringBuilder sb = new StringBuilder();
     sb.Append("<script language=\"javascript\"> \n");
     sb.Append("alert(\"" + msg.Trim() + "\"); \n");
     sb.Append("</script>\n");
     Page.RegisterClientScriptBlock("AlertJs", sb.ToString());
 }
Example #8
0
File: Js.cs Project: pczy/Pub.Class
 /// <summary>
 /// 清空指定注册的JS代码
 /// </summary>
 /// <param name="Page">指定Page</param>
 /// <param name="isTop">是否在头部/否则在尾部</param>
 /// <param name="IDStr">Key</param>
 public static void Run(System.Web.UI.Page Page, bool isTop, string IDStr) {
     if (isTop) Page.RegisterClientScriptBlock(IDStr, ""); else Page.RegisterStartupScript(IDStr, "");
 }
Example #9
0
File: Js.cs Project: pczy/Pub.Class
 //#endregion
 //#region Import/loadCss/AddAttr/chkFormData
 /// <summary>
 /// 注册一个处部JS文件/或CSS文件
 /// </summary>
 /// <param name="Page">指定页</param>
 /// <param name="filePath">文件</param>
 /// <param name="isTop">是否在头部/否则在尾部</param>
 public static void Import(System.Web.UI.Page Page, string filePath, bool isTop) {
     StringBuilder sb = new StringBuilder();
     if (filePath.ToLower().Substring(filePath.Length - 3, 3) == ".js") {
         sb.Append("<script language=\"JavaScript\" src=\"" + filePath + "\" type=\"text/javascript\"></script>\n");
         if (isTop) Page.RegisterClientScriptBlock("TopJs", sb.ToString()); else Page.RegisterStartupScript("BottomJs", sb.ToString());
     }
     if (filePath.ToLower().Substring(filePath.Length - 4, 4) == ".css") {
         LoadCss(Page, filePath);
     }
 }
Example #10
0
 /// <summary>
 /// obtém o script que permite esconder/mostrar um elemento em javascript
 /// </summary>
 /// <returns></returns>
 public static void registerShowHideScript( System.Web.UI.Page page )
 {
     string script =	@"
             <script language='javascript'>
                 var imagePath = '"+ OrionGlobals.getCommonImagePath("") [email protected]"';
                 function show(id,img) {
                     var obj = document.getElementById(id);
                     if( 'none' != obj.style.display ) {
                         obj.style.display = 'none';
                         img.src = imagePath + 'plus.gif';
                     } else {
                         obj.style.display = 'inline';
                         img.src = imagePath + 'minus.gif';
                     }
                 }
             </script>
         ";
     page.RegisterClientScriptBlock("showhide", script );
 }