Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

jQuery Localized Confirmation Box

3.00/5 (3 votes)
13 Jul 2012CPOL 13.2K  
A localized confirmation box in jQuery

We were facing an issue that our French customers wanted a confirm box with button captions in French, i.e., they wanted OK/Cancel captions in French. We had tried so much on Internet Explorer and some other crap in other browsers. But we finally found a solution.

jQuery Easy Confirm Dialog Plug in

This is very simple and all we need is a stylesheet and jquery-ui.js.

The code is given below.

HTML Page Codes

XML
<head runat="server">
    <title></title>
       <link href="Styles/EasyConfirm.css" 
       rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.7.js" 
    type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" 
     type="text/javascript"></script>
    
     <script src="Scripts/jquery.easy-confirm-dialog.js" 
     type="text/javascript"></script>
  </head>

 <asp:Button ID="ClickBtn" runat="server" 
 Text="Click" OnClick="ClickBtn_Click" />
    <a href="#" id="yesno">Normal test with yes and no</a>
    <script type="text/javascript">
        $("#<%=ClickBtn.ClientID %>").easyconfirm
        ({ locale: { title: '<%=TitleFor %>', 
               text: '<%=Message %>', 
               button: ['<%=CancelButton %>', '<%=OkButton %>']} });

        $("#<%=ClickBtn.ClientID %>").click(function () {           
                alert("You clicked yes");           
        }); 

The Code Behind

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

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        public string TitleFor
        {
            get;
            set;
        }

        public string Message
        {
            get;
            set;
        }

        public string OkButton
        {
            get;
            set;
        }

        public string CancelButton
        {
            get;
            set;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            TitleFor = "Please Confirm";
            Message = "Do you agree ?";
            OkButton = "bonjour/ok";
            CancelButton = "Bonjour/Cancel";
        }

        protected void ClickBtn_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)