How to show MessageBox on asp.net?

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

提交回复
热议问题