Hopes

          Start Here..

           

          Asp.net中用來代替Response.Write("");

          如果直接在頁面中使用Response.Write("<script>alert('錯誤信息');</script>"); 點擊確定以后,可能會造成頁面“錯位”;

           把代碼封裝到一個類中(就叫PageHelper.cs吧),在其他頁面也可以方便的調用;

           例如在其他頁面調用:Page.Alert(this,"錯語信息"); 效果和上面的代碼是一樣的,要說不同點吧?就是這個寫法比上面的完美好多。

          調用的時候也可以有第二個參數,即轉跳地址:  Page.Alert(this,"警告提示~","~/Default.aspx");

           

          復制代碼
          /**
           * 
           * 功明說明:頁面助手類,實現彈出警告對話框;
           * 
           * Design By: 追憶;
           * 
           * 創建日期:2011-01-11
           * 
           * 
          */

          using System;
          using System.Collections.Generic;
          using System.Text;
          using System.Web.UI;

          namespace NewsSystem.CommonUtility
          {
              
          public static class PageHelper
              {
                  
          public static void Alert(Page objPage, string message)
                  {
                      
          string key = "AlertMessage";
                      
          string script = string.Format("alert('{0}')", message);
                      objPage.ClientScript.RegisterStartupScript(
          typeof(Page), key, script, true);
                  }

                  
          public static void Alert(Page objPage, string message, string url)
                  {
                      
          string key = "AlertMessage";
                      
          string script = String.Format("alert('{0}');window.location='{1}';", message, url);
                      objPage.ClientScript.RegisterStartupScript(
          typeof(Page), key, script, true);
                  }
              }
          }

          posted on 2012-05-10 21:53 ** 閱讀(529) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          公告

          你好!

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章分類

          文章檔案

          新聞檔案

          相冊

          收藏夾

          C#學習

          友情鏈接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 泸定县| 彭山县| 墨江| 夏津县| 肃北| 色达县| 永嘉县| 甘洛县| 治多县| 监利县| 蒙自县| 盐城市| 济宁市| 视频| 崇文区| 莱西市| 德化县| 沅江市| 大足县| 鄄城县| 金溪县| 大洼县| 四平市| 宽城| 彰武县| 台安县| 平湖市| 徐州市| 满洲里市| 大庆市| 抚宁县| 雅安市| 台前县| 沁源县| 象州县| 克什克腾旗| 新巴尔虎左旗| 阳曲县| 茶陵县| 庆阳市| 清水河县|