Thursday, July 12, 2012

JQuery Localized Confirm Box

We were facing an issue that our french customers want confirm box with button captions in french, ie they want ok/cancel captions in french.
We had tried so much to localize the javascript confirm box, but we failed because the confirm box use the win32 api in internet explorer and some other craps in other browsers.
But we finally find one solution.

jQuery Easy Confirm Dialog plugin's

This is very simple and only we need is a style sheet and a jquery-ui.js.

The code given below.

 

 HTML Page codes.


<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 is

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)
        {
          
        }
    }
}


    </script>

3 comments:

  1. Wow really very useful blog. Thanks for sharing it....

    Online Study Courses

    ReplyDelete
  2. I truly like to reading your post. Thank you so much for taking the time to share such a nice information.
    web grid

    ReplyDelete
  3. hi nice article. coding is clearly explanied. really i like this. keep sharing on.................

    ReplyDelete