How to show MessageBox on asp.net?

前端 未结 9 1676
悲&欢浪女
悲&欢浪女 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:47

    You could just simply write but you have to use JavaScript regardless.

    Page.ClientScript.RegisterStartupScript(Page.GetType(), "Message Box", "<script language = 'javascript'>alert('dd')</script>");
    
    0 讨论(0)
  • 2020-12-10 15:48

    MessageBox doesn't exist in ASP.NET. If you need functionality in the browser, like showing a message box, then you need to opt for javascript. ASP.NET provides you with means to inject javascript which gets rendered and executed when the html sent to the browser's loaded and displayed. You can use the following code in the Page_Load for example:

    Type cstype = this.GetType();
    
    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;
    
    // Check to see if the startup script is already registered.
    if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
    {
        String cstext = "alert('Hello World');";
        cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
    }
    

    This sample's taken from MSDN.

    0 讨论(0)
  • 2020-12-10 15:48

    Messagebox is for windows only. You have to use Javascript

    Alert('dd'); 
    
    0 讨论(0)
提交回复
热议问题