Display message in message box (pop up) in asp.net

Introduction: In this article I will explain how to display message in message box (pop up) in asp.net from server side (code behind)

Description:
Commonly we use the message box to show message of data insert, update, delete etc... Now I am going to explain the different ways to show a message:

Method 1:
C #:-
protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("<script type=\"text/javascript\">alert('Messagebox Pop up Alert!!!');</script>");
    }

VB:-
  Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button3.Click
        Response.Write("<script type=""text/javascript"">alert('Messagebox Pop up Alert!!!');</script>")
    End Sub

Method 2:
C #:-
protected void Button1_Click(object sender, EventArgs e)
    {
       Messagebox("Messagebox Pop up Alert!!!");

    }
private void Messagebox(string Message)
    {
        Label lblMessageBox = new Label();
        lblMessageBox.Text =
            "<script language='javascript'>" + Environment.NewLine +
            "window.alert('" + Message + "')</script>";
        Page.Controls.Add(lblMessageBox);
    }

VB:-
   Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
        Messagebox("Messagebox Pop up Alert!!!")
    End Sub
    Private Sub Messagebox(Message As String)
        Dim lblMessageBox As New Label()
        lblMessageBox.Text = (Convert.ToString("<script language='javascript'>" + Environment.NewLine + "window.alert('") & Message) + "')</script>"
        Page.Controls.Add(lblMessageBox)
    End Sub

Method 3:
C #:-
   protected void Button1_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Messagebox Pop up Alert!!!')", true);
    }

VB:-
  Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
        ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "alertMessage", "alert('Messagebox Pop up Alert!!!')", True)
    End Sub

Working Demo:
Display message in message box (pop up) in asp.net

In this article we learn display the message in message box in asp.net. I hope you enjoyed this article. 

Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget