You must Sign In to post a response.
  • Category: ASP.NET

    How to pop up a messagebox/alert box

    i want to display a messagebox or alert box for user conformation when a button clicked
  • #767324

    Refer below is the example to alert when a text box is empty..

    protected void Button1_Click(object sender, EventArgs e)
    if (TextBox1 .Text =="" )
    string sMandatoryFields = "number";
    ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "Hi", "alert('The Field " + sMandatoryFields + " is mandatory');", true);

    Hope this will help you

    Never lose hope..You never know what tomorrow will bring

  • #767344

    If you want to show confirmation message box for alert, then on button OnClientClick property just call one javascript function and check the confirmation message based on confirmation you can go a head or skip the process by setting return true/false.

    <asp:Button ID="btnConfirm" runat="server" OnClick = "btnConfirm_Click" Text = "Raise Confirm" OnClientClick = "Confirm()"/>

    function Confirm() {
    if (confirm("Do you want to save data?")) {
    return true;
    } else {
    return false;

    In confirmation we get Ok/Cancel, based on selection we can set return true/false in javascript based on return statement button OnClick event will trigger, if it is true onclick event will trigger or else it won't.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #768467
    try this

    <asp:Button ID="confirm" runat="server" OnClick = "confirm_Click" Text = "confirm" OnClientClick = "confirm()"/>

    function confirm() {
    jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
    jAlert('Confirmed: ' + r, 'Confirmation Results');

    Software Developer
    iFour Technolab Pvt. Ltd.

  • #768471
    you can use given code snippet in C# to show confirmation message box for alert

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsFormsApplication1
    public partial class Form1 : Form
    public Form1()

    private void Form1_Load(object sender, EventArgs e)

    MessageBox.Show("Dot Net Spider is awesome.");

    MessageBox.Show("Dot Net Spider is awesome.",
    "Important Message");
    DialogResult result1 = MessageBox.Show("Is Dot Net Spider awesome?",
    "Important Question",

    DialogResult result3 = MessageBox.Show("Is Visual Basic awesome?",
    "The Question",

    if (result1 == DialogResult.Yes &&
    result2 == DialogResult.Yes &&
    result3 == DialogResult.No)
    MessageBox.Show("You answered yes, yes and no.");

    MessageBox.Show("Dot Net Spider is super.",
    "Important Note",


    Useful reference:

  • Sign In to post your comments