How to call window.alert(“message”); from C#?

后端 未结 10 2312
春和景丽
春和景丽 2021-02-07 05:18

I have my own exception based on some condition and want to raise an alert when control comes in this catch block

catch (ApplicationException ex)
{
    //want t         


        
相关标签:
10条回答
  • 2021-02-07 06:07

    Do you mean, a message box?

    MessageBox.Show("Error Message", "Error Title", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    

    More information here: http://msdn.microsoft.com/en-us/library/system.windows.forms.messagebox(v=VS.100).aspx

    0 讨论(0)
  • 2021-02-07 06:09

    You should try this.

    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Sakla Test');", true);

    0 讨论(0)
  • 2021-02-07 06:13

    Simple use this to show the alert message box in code behind.

    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Record Saved Sucessfully');", true);
    
    0 讨论(0)
  • 2021-02-07 06:14

    You can try this:

    Hope it works for you..

    `private void validateUserEntry()
    {
        // Checks the value of the text.
        if(serverName.Text.Length == 0)
        {
        // Initializes the variables to pass to the MessageBox.Show method.
        string message = "You did not enter a server name. Cancel this operation?";
        string caption = "Error Detected in Input";
        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
        DialogResult result;
    
        // Displays the MessageBox.
        result = MessageBox.Show(message, caption, buttons);
        if (result == System.Windows.Forms.DialogResult.Yes)
        {
         // Closes the parent form.
            this.Close();
        }
        }
    }` 
    
    0 讨论(0)
提交回复
热议问题