Hopes

          Start Here..

           

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

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

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

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

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

           

          復制代碼
          /**
           * 
           * 功明說明:頁面助手類,實現(xiàn)彈出警告對話框;
           * 
           * Design By: 追憶;
           * 
           * 創(chuàng)建日期: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 ** 閱讀(528) 評論(0)  編輯  收藏


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


          網站導航:
           

          導航

          統(tǒng)計

          公告

          你好!

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章分類

          文章檔案

          新聞檔案

          相冊

          收藏夾

          C#學習

          友情鏈接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 西丰县| 龙门县| 伊吾县| 丰台区| 克山县| 广灵县| 宁都县| 繁峙县| 安庆市| 兰坪| 广东省| 屯门区| 银川市| 邮箱| 遂川县| 龙南县| 万宁市| 县级市| 太湖县| 虞城县| 车致| 赫章县| 鄂州市| 佳木斯市| 青浦区| 平乐县| 大田县| 元氏县| 邵阳市| 宁强县| 娄底市| 鄂尔多斯市| 潍坊市| 庄浪县| 锡林浩特市| 马龙县| 边坝县| 台东县| 楚雄市| 屯昌县| 五华县|