How can I display a messagebox in ASP.NET?

前端 未结 13 2092
死守一世寂寞
死守一世寂寞 2020-11-30 11:30

I want to show a message box on the successful save of any item. I googled it and tried different solutions, but none of them worked. Here is the code I am using:

         


        
相关标签:
13条回答
  • 2020-11-30 11:57

    This method works fine for me:

    private void alert(string message)
    {
        Response.Write("<script>alert('" + message + "')</script>");
    }
    

    Example:

    protected void Page_Load(object sender, EventArgs e)
    {
        alert("Hello world!");
    }
    

    And when your page load yo will see something like this:

    I'm using .NET Framework 4.5 in Firefox.

    0 讨论(0)
  • 2020-11-30 11:57

    Alert message with redirect

    Response.Write("<script language='javascript'>window.alert('Popup message ');window.location='webform.aspx';</script>");

    Only alert message

    Response.Write("<script language='javascript'>window.alert('Popup message ')</script>");

    0 讨论(0)
  • 2020-11-30 11:58

    you can use clientscript. MSDN : Clientscript

    String scriptText = 
            "alert('sdsd');";
        ClientScript.RegisterOnSubmitStatement(this.GetType(), 
            "ConfirmSubmit", scriptText);
    

    try this

    ClientScript.RegisterStartupScript(this.GetType(), "JSScript", scriptText); 
    
    
    
    ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", scriptText); //use this 
    
    0 讨论(0)
  • 2020-11-30 12:00

    I use this and it works

    public void Messagebox(string xMessage)
    {
        Response.Write("<script>alert('" + xMessage + "')</script>");
    }
    

    And I call like this

        Messagebox("je suis la!");
    
    0 讨论(0)
  • 2020-11-30 12:04

    @freelancer If you are using ScriptManager then try this code for message..

    string script = "alert(\"Hello!\");";
    ScriptManager.RegisterStartupScript(this, GetType(), 
                          "ServerControlScript", script, true);
    
    0 讨论(0)
  • 2020-11-30 12:04

    Try This Code:Successfully

    Written on click Button.

    ScriptManager.RegisterStartupScript(this, GetType(),"alertMessage", "alert('Record Inserted Successfully');", true);
    
    0 讨论(0)
提交回复
热议问题