Search code examples
c#asp.netalertifyjs

Can't get Alertify messagebox to appear in asp.net


I am unable to get the AlertifyJS messagebox to work with my asp.net project.

I'm trying to make a reasonably simple website and would like to improve the default alert functionality.

I've viewed a number of other forums on this but unfortunately have not been able to figure out my issue.

Here is my .aspx code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="Test.WebForm4" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="Scripts/alertify.js" type="text/javascript"></script>
    <link href="Content/alertifyjs/alertify.css" rel="stylesheet" />
    <link href="Content/alertifyjs/themes/default.css" rel="stylesheet" />
<script type="text/javascript">
function Confirm() {
    alert("here");
            var confirm_value = document.createElement("INPUT");
            confirm_value.type = "hidden";
            confirm_value.name = "confirm_value";
    alert("here2");
    alertify.confirm('Do it', function (e) {

                if (e) {
                    $('#PrchBtnHiddenYes').click();
                    confirm_value.value = "Yes";

                } else {
                    $('#PrchBtnHiddenNo').click();
                    confirm_value.value = "No";                    
                }
    }).set('labels', { ok: 'Yes', cancel: 'No' });

    //alertify.confirm('Title', 'Message', function () { $('#PrchBtnHiddenYes').click(); confirm_value = "Yes"; }, function () { $('#PrchBtnHiddenNo').click(); confirm_value = "No"; }).set('labels', { ok: 'Yes', cancel: 'No' });
    alert("here3");
}   
</script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Button ID="PrchBtn" runat="server" class="PrchBtn" Text="Click Here" OnClientClick="Confirm(); return false;" />
        <asp:Button runat="server" ID="PrchBtnHiddenYes" ClientIDMode="Static" Style="display: none;" />
        <asp:Button runat="server" ID="PrchBtnHiddenNo" ClientIDMode="Static" Style="display: none;" />

    </form>
</body>
</html>

Here is my cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Test
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            PrchBtnHiddenNo.Click += PrchBtnHiddenNo_Click;
            PrchBtnHiddenYes.Click += PrchBtnHiddenYes_Click;
        }

        void PrchBtnHiddenYes_Click(object sender, EventArgs e)
        {
            string Success = "Success";
        }

        void PrchBtnHiddenNo_Click(object sender, EventArgs e)
        {
            string Failure = "Failure";
        }
    }
}

I'm not getting any error messages. For testing purposes, I have put 3 alerts in the javascript code. I get the first and second one but the alertify script doesn't fire and therefore neither does 3rd alert.

Thanks in advance.


Solution

  • seems your local alertify is not working. try this instead.

    <script src="//cdn.jsdelivr.net/npm/[email protected]/build/alertify.min.js"></script>
    
    
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/build/css/alertify.min.css"/>
    
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/build/css/themes/default.min.css"/>    
    
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/build/css/themes/bootstrap.min.css"/>