473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

MasterPage.InitializeCulture()': no suitable method found to override

JustRun
127 100+
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:
Expand|Select|Wrap|Line Numbers
  1.     public override void InitializeCulture()
  2.     {
  3.         string culture = Request.QueryString["lang"];
  4.         //string culture = Request.Form["cmbCulture"];
  5.  
  6.         if (string.IsNullOrEmpty(culture))
  7.             culture = "Auto";
  8.         //Use this
  9.         UICulture = culture;
  10.         Culture = culture;
  11.         //OR This
  12.         if (culture != "Auto")
  13.         {
  14.             System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(culture);
  15.             System.Threading.Thread.CurrentThread.CurrentCulture = ci;
  16.             System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
  17.         }
  18.  
  19.         base.InitializeCulture();
  20.     }
Oct 14 '08 #1
4 14151
Frinavale
9,735 Expert Mod 8TB
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
Oct 14 '08 #2
JustRun
127 100+
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,
Oct 15 '08 #3
@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?
Expand|Select|Wrap|Line Numbers
  1. using System.Globalization;
  2. using System.Threading;
  3. using System.Resources;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Web;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10.  
  11.  
  12. public partial class MasterPage : System.Web.UI.MasterPage
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.  
  17.     }
  18.  
  19.     protected void languageListIndexChange(object sender, EventArgs e)
  20.     {
  21.     }
  22.  
  23.     protected override void InitializeCulture()
  24.     {
  25.         if (Request.Form["languageList"] != null)
  26.         {
  27.  
  28.             String selectedLanguage = Request.Form["languageList"];
  29.             UICulture = selectedLanguage;
  30.             Culture = selectedLanguage;
  31.             Thread.CurrentThread.CurrentCulture =
  32.             CultureInfo.CreateSpecificCulture(selectedLanguage);
  33.             Thread.CurrentThread.CurrentUICulture = new
  34.             CultureInfo(selectedLanguage);
  35.  
  36.         }
  37.  
  38.         base.InitializeCulture();
  39.     }
  40. }
Oct 5 '11 #4
Frinavale
9,735 Expert Mod 8TB
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
Oct 5 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
1
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....
0
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...
9
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...
0
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...
1
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) {...
7
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...
0
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()"...
5
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....
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.