locked
Two Calendars with different cultures in the same page RRS feed

  • Question

  • User-2061835575 posted

    As the subject indicates!

    I have a web form where people such submit some personal info. The have to put some "Hijri" dates as well as "Gregorian" dates.

    Is there a way to have a calendar with "ar-SA" culture and another with "en-US" culture in the same page?

     

    Thanks in advance

    Tuesday, March 8, 2011 3:43 AM

Answers

  • User1007520750 posted

    Hi

    This can be done by using a creating a usercontrol for the matter, and sending the culture info with it. I've created the following page and UserControl.

    ASPX page:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" UICulture="auto" %>
    
    <%@ Register src="CalendarUC.ascx" tagname="CalendarUC1" tagprefix="uc1" %>
    <%@ Register src="CalendarUC.ascx" tagname="CalendarUC2" tagprefix="uc2" %>
    
    <!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>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <uc1:CalendarUC1 ID="CalendarUC1" runat="server" culture="en-US" />
            <uc2:CalendarUC2 ID="CalendarUC2" runat="server" culture="ar-SA" />
        </div>
        </form>
    </body>
    </html>

    CalendarUC.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CalendarUC.ascx.cs"
        Inherits="WebApplication1.CalendarUC" %>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
        </ContentTemplate>
    </asp:UpdatePanel>

    CalendarUC.ascx.cs

    using System;
    using System.Globalization;
    using System.Threading;
    
    public partial class CalendarUC : System.Web.UI.UserControl
    {
        private string localCulture;
    
        public string culture
        {
            get { return localCulture; }
            set { localCulture = value; }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
        }
    }

    This is still not in place because the result is two calendars with the last culture set. I've tried to follow this instruction, and add an override to the 'FrameworkInitialize' in the CultureUC codebehined:

    protected override void FrameworkInitialize()
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
    }

    But here the problem is that this is evaluated long before the property is sat, so the culture property is null at that point.

    Anyone has a suggestion?

    Amit

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 8, 2011 5:20 AM