Hii nauna,
Please refer below sample.
Global Resources
Resource.resx
Name |
Value |
Greetings |
Hello, I am Shailesh Yadav |
Introduction |
I Completed my graduation Mumbai University with Bachelor's Degree In Information Technology |
Resource.fr.resx
Name |
Value |
Greetings |
Bonjour, je suis Shailesh Yadav |
Introduction |
J'ai terminé mes études à l'Université de Mumbai avec un baccalauréat en technologie de l'information |
HTML
MasterPage
Master.aspx
<html>
<head runat="server">
<title></title>
<style type="text/css">
body { font-family: Arial; font-size: 10pt; }
</style>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="lblSelect" runat="server">Select Languages:</asp:Label>
<asp:DropDownList ID="ddlLanguages" runat="server"
AutoPostBack="true" OnSelectedIndexChanged="OnSelectedIndexChanged">
<asp:ListItem Text="English" Value="en-us" />
<asp:ListItem Text="French" Value="fr" />
</asp:DropDownList>
<hr />
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
</html>
Namespaces
C#
using System;
using System.Web;
using System.Web.UI;
using System.Threading;
using System.Globalization;
Code
C#
MasterPage.master.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Session["Index"] != null)
{
ddlLanguages.SelectedValue = Session["Index"].ToString();
ddlLanguages.SelectedIndex = Convert.ToInt32(Session["Index"].ToString());
}
else
{
ddlLanguages.SelectedValue = Thread.CurrentThread.CurrentCulture.Name;
}
}
}
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
Session["Languages"] = ddlLanguages.SelectedValue;
HttpCookie cookie = new HttpCookie("cultureInfo");
cookie.Value = ddlLanguages.SelectedValue;
Response.Cookies.Add(cookie);
Thread.CurrentThread.CurrentCulture = new CultureInfo(ddlLanguages.SelectedValue);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(ddlLanguages.SelectedValue);
if (cookie.Value == "en-us")
{
Session["Index"] = 0;
}
else if (cookie.Value == "fr")
{
Session["Index"] = 1;
}
}
Default Page
HTML
Default.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<span><strong><%=Resources.Resource.Greetings %></strong></span><br />
<span><%=Resources.Resource.Introduction %></span>
</asp:Content>
Global Page
C#
Global.asax
<script RunAt="server">
void Application_BeginRequest(Object sender, EventArgs e)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies["CultureInfo"];
if (cookie != null && cookie.Value != null)
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cookie.Value);
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cookie.Value);
}
else
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en");
}
}
</script>
Screenshot