473,325 Members | 2,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,325 software developers and data experts.

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...Current...UICulture..= new
CultureInfo(..Session("LangCode")...); } .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 ResourceProviderFactory, and I found the
process sequence is Provider.GetObject()., 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 2097
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*******@hotmail.com> wrote in message news:uL**************@TK2MSFTNGP09.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...Current...UICulture..=
new CultureInfo(..Session("LangCode")...); } .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 ResourceProviderFactory, and I
found the process sequence is Provider.GetObject()., 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****************@TK2MSFTNGP09.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*******@hotmail.com> wrote in message
news:uL**************@TK2MSFTNGP09.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...Current...UICulture..= new
CultureInfo(..Session("LangCode")...); } .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 ResourceProviderFactory, and I
found the process sequence is Provider.GetObject()., 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 InitializeCulture 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*******@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP12.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****************@TK2MSFTNGP09.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*******@hotmail.com> wrote in message news:uL**************@TK2MSFTNGP09.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...Current...UICulture..= new CultureInfo(..Session("LangCode")...); } .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 ResourceProviderFactory, and I found the process sequence is
Provider.GetObject()., 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 CustomeResourceProvider --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****************@TK2MSFTNGP12.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 InitializeCulture 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*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.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****************@TK2MSFTNGP09.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*******@hotmail.com> wrote in message
news:uL**************@TK2MSFTNGP09.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...Current...UICulture..= new
CultureInfo(..Session("LangCode")...); } .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
ResourceProviderFactory, and I found the process sequence is
Provider.GetObject()., 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
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
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...
34
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...
2
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...
1
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...
4
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...
4
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...
4
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...
2
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.