By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,954 Members | 1,354 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,954 IT Pros & Developers. It's quick & easy.

How to switch language on the runtime in asp.net2

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.