I need to pass the globalization resource language which is selected from the first page to the next page. Please follow the images and code segments and tell me whats wrong with it.
1) I'm getting the language from the drop down using below code
protected void Button1_Click(object sender, EventArgs e)
{
BasePage.CultureName = DropDownList1.SelectedItem.Value.ToString();
Response.Redirect("Page1.aspx");
}
2) Passing it to this function
public class BasePage : System.Web.UI.Page
{
public BasePage()
{
}
static string cultureName;
public static string CultureName
{
return cultureName;
}
set
{
cultureName = value;
}
}
protected override void InitializeCulture()
{
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(cultureName);
Thread.CurrentThread.CurrentUICulture = new
CultureInfo(cultureName);
base.InitializeCulture();
}
3) Passed variable is reading from here by inheriting it using the BasePage class
public partial class Page1 : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
4) ASPX File
<pre>
<%@ Page Language="C#" AutoEventWireup="true"CodeBehind="Page1.aspx.cs"
meta:resourcekey="PageResource1" Inherits="Globalization.Page1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label2" runat="server"
meta:resourcekey="Label2Resource1" />
</div>
<asp:Button ID="Button1" runat="server"
meta:resourcekey="ButtonResource1"/>
</form>
</body>
</html>
</pre>
5) Please refer the attached images for resource files. I have done these steps. But its not working. Please help me . :-)
I understood my mistake. The above code is working fine and its passing the language to next page also. The problem was I was using local resources and I added resx files only for 1 page. The resx file should be added to both the pages in order to get the expected result.