Hi,
I'm trying to develop a MultiLanguage web site using ASP.NET 2.0 with C#
My problem is: I want to make my MasterPage support switching among languages, but when i put the "InitializeCulture()" inside the masterpage.cs, I got this erreor:
MasterPage.InitializeCulture()': no suitable method found to override
Note the following code works fine with xxx.aspx page, but not with MasterPage
Here is my code: - public override void InitializeCulture()
-
{
-
string culture = Request.QueryString["lang"];
-
//string culture = Request.Form["cmbCulture"];
-
-
if (string.IsNullOrEmpty(culture))
-
culture = "Auto";
-
//Use this
-
UICulture = culture;
-
Culture = culture;
-
//OR This
-
if (culture != "Auto")
-
{
-
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(culture);
-
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
-
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
-
}
-
-
base.InitializeCulture();
-
}
4 14151
The MasterPage class is used as a template for your web application.
When an HTTP request is made for a page at run time, the master page and content pages are combined into a single class with the same name as the content pages. The resulting compiled, merged class derives from the Page class.
This means that you cannot override the InitializeCulture method in the MasterPage page class. You override this method in your aspx page.
-Frinny
Yes Frinny,
Thank you, I got it, I created a BaseClass.cs. this class inherit System.Web.UI.Page and all my xxx.aspx inherit this class.
Thank you,
@JustRun
I'm trying to do the same thing and getting the same error, here's my code below. I'm new to C# can either of you explain further how to override my method in my aspx page? -
using System.Globalization;
-
using System.Threading;
-
using System.Resources;
-
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Web;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
-
-
public partial class MasterPage : System.Web.UI.MasterPage
-
{
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
-
}
-
-
protected void languageListIndexChange(object sender, EventArgs e)
-
{
-
}
-
-
protected override void InitializeCulture()
-
{
-
if (Request.Form["languageList"] != null)
-
{
-
-
String selectedLanguage = Request.Form["languageList"];
-
UICulture = selectedLanguage;
-
Culture = selectedLanguage;
-
Thread.CurrentThread.CurrentCulture =
-
CultureInfo.CreateSpecificCulture(selectedLanguage);
-
Thread.CurrentThread.CurrentUICulture = new
-
CultureInfo(selectedLanguage);
-
-
}
-
-
base.InitializeCulture();
-
}
-
}
Garychappel,
To fix this problem remove the protected override void InitializeCulture() method from the MasterPage.
Put it into your ASPX pages instead.
See my explanation for why in post #2 in this thread.
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Hai Nguyen |
last post by:
Would anybody please tell me what is this error and what i should do
I have 5 files: page1.aspx,page1.aspx.cs; page2.aspx.page2.aspx.cs and page3.cs
both page1.aspx.cs and page2.aspx.cs inherit...
|
by: Daves |
last post by:
I am using 2.0 masterpages. All content pages use some common variables, for
example the DB connection string. Also some pages return links which are
located in a "sublink" area in the masterpage....
|
by: Mark Parter |
last post by:
I've "converted" the code at http://www.eggheadcafe.com/articles/20040613.asp
to VB.NET as I'd like to implement this as my application uses quite complex
GridViews and various other controls on...
|
by: User |
last post by:
OK, I asked in a reply, but I've wasted far too long so I'm going to put
a new post out there in hopes that it will be more visible.
I have a MasterPage. I want to call a method declared in that...
|
by: Maury |
last post by:
Hello,
I ovverride the method InitializeCulture
of a page to change programmatically
a language in a site, I would like to do this
after the user clicks on a button, but the
button_click event...
|
by: ad |
last post by:
Hi,
I have set the this.Page.Theme in a MasterPage, but it no affect.
I have set break point at this line, but it never execute.
void Page_PreInit(object sender, System.EventArgs args)
{...
|
by: WT |
last post by:
Hello,
It seems that when a control is set into a ContentPlaceHolder in a page
using a MasterPage, it's id is change and FindControl(ID) no more works, is
it normal, how to override this or...
|
by: maz77 |
last post by:
I've made my Masterpage with a Header, a LeftBar and a Content but only
the Content is a COntentPlaceHolder; I've changed the language of all
controls in Content overriding "InizializeCulture()"...
|
by: =?Utf-8?B?SGVyYg==?= |
last post by:
My long-running ASP application just stopped working today. I rebuilt and
republished, but to no avail.
The full error is:
Server Error in '/NuclearDedication' Application....
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |