Click here to Skip to main content
11,703,632 members (66,517 online)
Click here to Skip to main content

JQuery Confirm Box

, 15 Jul 2012 CPOL 32K 3
Rate this:
Please Sign up or sign in to vote.
JQuery Confirm Box is very simple, which can be easily customized.






JQuery Confirm Box is very simple, which can be easily customized. We can give manual values for button captions.

The custom box seems like the pic on the attachment. 


 The html page is below  

<%@ Page Language="C#" AutoEventWireup"true" CodeBehind="JqueryConfirm.aspx.cs"
    Inherits="SetCultureSample.JqueryConfirm.JqueryConfirm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title> 
    <link href="../Styles/jquery.confirm.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.confirm.js" type="text/javascript"></script>
    <script type="text/javascript">
     
            function ShowConfirm(Title, Message, OkBtnCaption, CancelBtnCaption, ButtonID) {
                var elem = $(this).closest('.item');               
             
                $.confirm({
                    'title': Title,
                    'message': Message,
                    'buttons': {
                        OkBtnCaption: {
                            'class': 'blue',
                            'action': function () { $('#' + ButtonID).click(); },
                            'id': 'okBtn'
                        },
                        CancelBtnCaption: {
                            'class': 'gray',
                            'action': function () { },
                            'id': 'cancelBtn'
                        }
                   }
                });
                return false;
            }   
      </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    </div>
    
    </form>
</body>
</html>
Here we are passing parameters to this method, and ShowConfirm method append the values to the confirm box.
<link href="../Styles/jquery.confirm.css" rel="stylesheet" type="text/css" />
  <script src="../Scripts/jquery.confirm.js" type="text/javascript"></script>
Here you need to use a stylesheet jquery.confirm.css and a jquery file jquery.confirm.js.

  The code behind is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SetCultureSample.JqueryConfirm
{
    public partial class JqueryConfirm : System.Web.UI.Page
    {
        /// <summary>
        /// Gets or sets the title for.
        /// </summary>
        /// <value>The title for.</value>
        public string TitleFor
        {
            get;
            set;
        }
        /// <summary>
        /// Gets or sets the message.
        /// </summary>
        /// <value>The message.</value>
        public string Message
        {
            get;
            set;
        }
        /// <summary>
        /// Gets or sets the ok button.
        /// </summary>
        /// <value>The ok button.</value>
        public string OkButton
        {
            get;
            set;
        }
        /// <summary>
        /// Gets or sets the cancel button.
        /// </summary>
        /// <value>The cancel button.</value>
        public string CancelButton
        {
            get;
            set;
        }
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            TitleFor = "Please Confirm";
            Message = "Do you agree ?";
            OkButton = "bonjour/ok";
            CancelButton = "Bon/Cancel";          
            Button1.Attributes.Add("onclick", "javascript:return ShowConfirm('" + TitleFor + "','" + Message + "','" + OkButton + "','" + CancelButton + "','" + this.Button1.ClientID + "');");
        }
        /// <summary>
        /// Handles the Click event of the Button1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Button1_Click(object sender, EventArgs e)
        {
                     
        }
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Christopher John Paul
Software Developer
India India
I am a software developer with a passion to develop innovative ideas.

You may also be interested in...

Comments and Discussions

 
QuestionJquery confirmation box Pin
Member 80593932-Apr-13 19:55
memberMember 80593932-Apr-13 19:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150819.1 | Last Updated 15 Jul 2012
Article Copyright 2012 by Christopher John Paul
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid