How to show MessageBox on asp.net?

前端 未结 9 1698
悲&欢浪女
悲&欢浪女 2020-12-10 15:21

if I need to show a MessageBox on my ASP.NET WebForm, how to do it?

I try: Messagebox.show(\"dd\");

But it\'s not working.

9条回答
  •  攒了一身酷
    2020-12-10 15:31

    I took the code from the brilliant @KrisVanDerMast and made it wrapped up in a static method that can be called as many times as you want on the same page!

    /// 
    /// Shows a basic MessageBox on the passed in page
    /// 
    /// The Page object to show the message on
    /// The message to show
    /// 
    public static ShowMessageBox(Page page, string message)
    {
        Type cstype = page.GetType();
    
        // Get a ClientScriptManager reference from the Page class.
        ClientScriptManager cs = page.ClientScript;
    
        // Find the first unregistered script number
        int ScriptNumber = 0;
        bool ScriptRegistered = false;
        do
        {
            ScriptNumber++;
            ScriptRegistered = cs.IsStartupScriptRegistered(cstype, "PopupScript" + ScriptNumber);
        } while (ScriptRegistered == true);
    
        //Execute the new script number that we found
        cs.RegisterStartupScript(cstype, "PopupScript" + ScriptNumber, "alert('" + message + "');", true);
    }
    

提交回复
热议问题