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 :

Sign In to post your comments