Alert方法

     public   class  ClientScript
    
{
        
/// <summary>
        
/// 
        
/// </summary>
        
/// <param name="message"></param>
        
/// <param name="curentPage"></param>

        public static void ShowMessage(string message, Control curentPage)
        
{
            ShowMessage(message, curentPage, 
0);
        }


        
/// <summary>
        
/// 用弹出对话框显示消息alert("test")
        
/// </summary>
        
/// <param name="message"></param>
        
/// <param name="curentPage"></param>
        
/// <param name="messageID">messageID > 0,表示还需要继续显示消息</param>

        public static void ShowMessage(string message, Control curentPage, int messageID)
        
{
            
//<script language='javascript' type='text/javascript'>alert('保存成功!');window.opener=null;window.close()</script>

            StringBuilder sb 
= new StringBuilder();
            sb.Append(
"<script language='javascript' type='text/javascript'>");
            sb.Append(
"function ShowMessage" + messageID.ToString() + "() {\n");
            sb.Append(
"var objShowMessage=document.getElementById('showMessage');\n");
            sb.Append(
"if(objShowMessage) {\n");
            sb.Append(
"if(objShowMessage.value==1) {\n");
            sb.Append(
"alert('" + message + "');\n");
            
if ( 0 == messageID )
            
{
                sb.Append(
"objShowMessage.value=0;\n");
            }

            sb.Append(
"}\n");    //if
            sb.Append("}\n");    //if
            sb.Append("}\n");    //function

            sb.Append(
"window.addOnLoadListener(ShowMessage" + messageID.ToString() +  ");\n");
            sb.Append(
"</script>");

            Page page 
= curentPage as Page;
            
if (page != null)
            
{
                
if (!page.ClientScript.IsClientScriptBlockRegistered(page.GetType(), "CLIENT_SCRIPT_SHOW_MESSAGE"))
                
{
                    page.ClientScript.RegisterClientScriptBlock(page.GetType(),
"CLIENT_SCRIPT_SHOW_MESSAGE" , sb.ToString());
                }

            }

        }

    }
aspx:
   < script >
    
function  OnWindowLoad()
    
{
        
for(var i = 0; i < window.onloadListeners.length; i++{
            
var func = window.onloadListeners[i];
            func.call(
this);
        }

    }

    window.onloadListeners 
=   new  Array();
    window.addOnLoadListener 
=   function (listener) 
    
{
        window.onloadListeners[window.onloadListeners.length] 
= listener;
    }

    window.onload 
=  OnWindowLoad;
    
</ script >
    
< asp:HiddenField runat = " server "  ID = " showMessage "  Value = " 1 "   />

你可能感兴趣的:(alert)