弹出框不影响样式

/// <summary>
        /// 弹出对话框,并不影响css样式
        /// </summary>
        /// <param name="page">this.Page</param>
        /// <param name="scriptKey">脚本键值,必须唯一</param>
        /// <param name="message">显示的消息内容</param>

        public static void ShowMessage(System.Web.UI.Page page, string scriptKey, string message)
        {
            System.Web.UI.ClientScriptManager csm = page.ClientScript;
            System.Text.StringBuilder strScript = new System.Text.StringBuilder();
            if (!csm.IsClientScriptBlockRegistered(scriptKey))
            {
                strScript.Append("alert('");
                strScript.Append(message);
                strScript.Append("');");
                csm.RegisterClientScriptBlock(page.GetType(), scriptKey, strScript.ToString(), true);
            }
        }

把这个方法添加到项目中,直接调用,传入一定的参数就可以了。其中Page可以传this.Page,脚本值可以随意填写,message就是弹出的文字。

posted @ 2010-05-10 17:21  GeliBear  Views(338)  Comments(0)    收藏  举报