473,785 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to switch language on the runtime in asp.net2

The question sound simple -- I had a multilingual site, I give a button on
each page to allow user switch to different language, and of cause I want to
use asp.net 2 globalization mechanism. So what I did is 1. make my controls
to use new resource expression, 2.create a session variable to record the
current language 3. and put a logic in page_load {
....Thread...Cu rrent...UICultu re..= new
CultureInfo(..S ession("LangCod e")...); } .But when I traced the process, I
found the resource actually is populated before the page_load function.
Well, the reason I know this is because I created my own customized resource
provider factory inheriting from ResourceProvide rFactory, and I found the
process sequence is Provider.GetObj ect()., then Page_Load().

Well, I can try to put page_init event , but I guess someone here must know
the solution already. Appreciate any comment.
Mar 10 '06 #1
4 2121
Have you considered, instead of using Page_Load and Session,
caching the culture and retrieving the currentculture from the Cache ?

See sample code you can adapt at :

http://msdn2.microsoft.com/en-us/lib.../9b1d2yze.aspx

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"walter" <ca*******@hotm ail.com> wrote in message news:uL******** ******@TK2MSFTN GP09.phx.gbl...
The question sound simple -- I had a multilingual site, I give a button on each page to allow user
switch to different language, and of cause I want to use asp.net 2 globalization mechanism. So
what I did is 1. make my controls to use new resource expression, 2.create a session variable to
record the current language 3. and put a logic in page_load { ...Thread...Cur rent...UICultur e..=
new CultureInfo(..S ession("LangCod e")...); } .But when I traced the process, I found the resource
actually is populated before the page_load function. Well, the reason I know this is because I
created my own customized resource provider factory inheriting from ResourceProvide rFactory, and I
found the process sequence is Provider.GetObj ect()., then Page_Load().

Well, I can try to put page_init event , but I guess someone here must know the solution already.
Appreciate any comment.

Mar 10 '06 #2
Juan, thanks for the information. I think there are two problems in your
suggestion :

1. Cache is on application level whereas my requirement is on per
user/session level.Well, even I can play with it ,but it looks like a bit
overkill.

2. I just did a trace, actually the resource is retrieved even before the
"Begin PreInit" event, which means in order to switch the language , I have
to put information somewhere, then resubmit the page again. It's not a nice
thing, do you agree?

I'm kind of stuck here. Welcome any comment.

"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Have you considered, instead of using Page_Load and Session,
caching the culture and retrieving the currentculture from the Cache ?

See sample code you can adapt at :

http://msdn2.microsoft.com/en-us/lib.../9b1d2yze.aspx

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"walter" <ca*******@hotm ail.com> wrote in message
news:uL******** ******@TK2MSFTN GP09.phx.gbl...
The question sound simple -- I had a multilingual site, I give a button
on each page to allow user switch to different language, and of cause I
want to use asp.net 2 globalization mechanism. So what I did is 1. make
my controls to use new resource expression, 2.create a session variable
to record the current language 3. and put a logic in page_load {
...Thread...Cur rent...UICultur e..= new
CultureInfo(..S ession("LangCod e")...); } .But when I traced the process,
I found the resource actually is populated before the page_load function.
Well, the reason I know this is because I created my own customized
resource provider factory inheriting from ResourceProvide rFactory, and I
found the process sequence is Provider.GetObj ect()., then Page_Load().

Well, I can try to put page_init event , but I guess someone here must
know the solution already. Appreciate any comment.


Mar 10 '06 #3
re:
2. I just did a trace, actually the resource is retrieved even before the "Begin PreInit" event,
which means in order to switch the language , I have to put information somewhere, then resubmit
the page again.
The InitializeCultu re method is called very early in the page life cycle,
before controls are created or properties are set for the page.

Therefore, to read values that are passed to the page from controls,
you must get them directly from the request using the Form collection.

There's a good explanation for the process, and sample code, at :

http://msdn2.microsoft.com/en-us/lib...08(VS.80).aspx

For a backgrounder on methods of implementing ASP.NET web page resources
( although you look quite adept at it already ), see :

http://msdn2.microsoft.com/en-us/library/ms227427.aspx


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"walter" <ca*******@hotm ail.com> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Juan, thanks for the information. I think there are two problems in your suggestion :

1. Cache is on application level whereas my requirement is on per user/session level.Well, even I
can play with it ,but it looks like a bit overkill.

2. I just did a trace, actually the resource is retrieved even before the "Begin PreInit" event,
which means in order to switch the language , I have to put information somewhere, then resubmit
the page again. It's not a nice thing, do you agree?

I'm kind of stuck here. Welcome any comment.

"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Have you considered, instead of using Page_Load and Session,
caching the culture and retrieving the currentculture from the Cache ?

See sample code you can adapt at :

http://msdn2.microsoft.com/en-us/lib.../9b1d2yze.aspx

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"walter" <ca*******@hotm ail.com> wrote in message news:uL******** ******@TK2MSFTN GP09.phx.gbl...
The question sound simple -- I had a multilingual site, I give a button on each page to allow
user switch to different language, and of cause I want to use asp.net 2 globalization mechanism.
So what I did is 1. make my controls to use new resource expression, 2.create a session variable
to record the current language 3. and put a logic in page_load {
...Thread...Cur rent...UICultur e..= new CultureInfo(..S ession("LangCod e")...); } .But when I
traced the process, I found the resource actually is populated before the page_load function.
Well, the reason I know this is because I created my own customized resource provider factory
inheriting from ResourceProvide rFactory, and I found the process sequence is
Provider.GetObj ect()., then Page_Load().

Well, I can try to put page_init event , but I guess someone here must know the solution
already. Appreciate any comment.



Mar 10 '06 #4
Juan, thanks a lot.That doc solve my problem . An additional question is on
the my CustomeResource Provider --I want to store the resource in database.
But looks like I need to implement a language tree logic in my SQL tier to
find the proper resource root if the current culture is not available. Just
want to confirm if this is the right understanding.

"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:uC******** ********@TK2MSF TNGP12.phx.gbl. ..
re:
2. I just did a trace, actually the resource is retrieved even before the
"Begin PreInit" event, which means in order to switch the language , I
have to put information somewhere, then resubmit the page again.


The InitializeCultu re method is called very early in the page life cycle,
before controls are created or properties are set for the page.

Therefore, to read values that are passed to the page from controls,
you must get them directly from the request using the Form collection.

There's a good explanation for the process, and sample code, at :

http://msdn2.microsoft.com/en-us/lib...08(VS.80).aspx

For a backgrounder on methods of implementing ASP.NET web page resources
( although you look quite adept at it already ), see :

http://msdn2.microsoft.com/en-us/library/ms227427.aspx


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"walter" <ca*******@hotm ail.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Juan, thanks for the information. I think there are two problems in your
suggestion :

1. Cache is on application level whereas my requirement is on per
user/session level.Well, even I can play with it ,but it looks like a bit
overkill.

2. I just did a trace, actually the resource is retrieved even before the
"Begin PreInit" event, which means in order to switch the language , I
have to put information somewhere, then resubmit the page again. It's not
a nice thing, do you agree?

I'm kind of stuck here. Welcome any comment.

"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Have you considered, instead of using Page_Load and Session,
caching the culture and retrieving the currentculture from the Cache ?

See sample code you can adapt at :

http://msdn2.microsoft.com/en-us/lib.../9b1d2yze.aspx

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"walter" <ca*******@hotm ail.com> wrote in message
news:uL******** ******@TK2MSFTN GP09.phx.gbl...
The question sound simple -- I had a multilingual site, I give a button
on each page to allow user switch to different language, and of cause I
want to use asp.net 2 globalization mechanism. So what I did is 1. make
my controls to use new resource expression, 2.create a session variable
to record the current language 3. and put a logic in page_load {
...Thread...Cur rent...UICultur e..= new
CultureInfo(..S ession("LangCod e")...); } .But when I traced the
process, I found the resource actually is populated before the
page_load function. Well, the reason I know this is because I created
my own customized resource provider factory inheriting from
ResourceProvide rFactory, and I found the process sequence is
Provider.GetObj ect()., then Page_Load().

Well, I can try to put page_init event , but I guess someone here must
know the solution already. Appreciate any comment.



Mar 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
8111
by: Robert Scheer | last post by:
Hi. In VBScript I can use a Select Case statement like that: Select Case X Case 1 to 10 'X is between 1 and 10 Case 11,14,16 'X is 11 or 14 or 16 End Select
11
3771
by: hasadh | last post by:
Hi, is the assemly code for if..else and switch statements similar. I would like to know if switch also uses value comparison for each case internally or does it jump to the case directly at the assembly level ? for a performance critical application is it better to to use switch case or accomplish the same using fn pointers ?
34
53442
by: Duncan McNutt [BSDM] | last post by:
Is it possible to have ranges or patterns in a case ? If not, why wasnt this designed in to make it easier instead of listing every case value needed? -- Duncan McNutt Microsoft Product Deactivation Team --
2
1481
by: fred | last post by:
I tested following program gives runtime error: Unhandled Exception: System.InvalidProgramException: Common Language Runtime detected an invalid program. using System; public class SwitchTest { static void Main() { const int i = 1;
1
1695
by: Winista | last post by:
I have a library that reads PDF file and manipilates its content. And I use SharpZip library to decompress the streams included in PDF file. All well and good. I have 3 lines of my test code that takes a PDF file and spits out the required content from the file. It all works fine in .Net.1. environment. Now I wrote the same 3 lines of code in .Net2.0 console test application and use the assemblies for PDF library and SharpZip compiled...
4
2519
by: hvj | last post by:
I need to run a .NET1.1 program in a .NET2.0 CLR. The .NET1.1 exe starts correctly in .NET2.0. Now I want to debug in Visual Studio 2005. But when I try to open the .NET1.1 project, Visual Studio wants to convert it to .NET2.0 what I don't want. How can I make Visual Studio open a .NET1.1 project for me in order to attach to a .NET2.0 process in which it runs to debug it? Or is there a better way to reach my goal: debugging a .NET1.1...
4
1868
by: InnoCreate | last post by:
Hi everyone, I've developed a couple of asp.net1.1 websites and these are viewable using my mobile phone. I've now moved over to asp.net2 and i'm unable to view asp.net2 websites on my phone. I've stripped a page down to only output HTML4.01 and a single line of text with no formatting and it's still not viewable. Can anyone help me - i don't want to develop a asp.net2 mobile website - i want to develop a standard asp.net2 website that...
4
1937
by: dreamamit2001 | last post by:
Hi, I would like to know the ASP.NET2.0's(Controls, Menubar, Validations, Object Data Souce Controls, Treeview Control) compatibility with IE5.0 browser on Mac OS. If I don't use Client side Vbscript and Activex control, will the site developed in Asp.net2.0 work fine on IE5.0 Mac Os? Any body who has viewed the working of ASP.NET2.0 with rich controls
2
1062
by: H | last post by:
Using VS2005 Created new website. Placed one button, one label on the form. In the click event of the button, I set the text of the label to "Clicked!". That's it. It works locally thru VS2005. I publish the website to the local IIS, that works ok. I upload the published directory to my site online and I get a 'Runtime error'. This is a basic helloworld. The site has ASP.NET2.0 enabled. I must be missing something basic. ( I...
0
10350
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9957
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7505
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.