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

Aspx-files sharing the same codebehind?

P: n/a
Hi all,

I've been thinking of about adding new languages to our website and is
currently investigating how this could be done. And I know that one way to go
would be to create new aspx-pages with new codebehinds for each page I want
to have translated.

But my question is - is it ok to keep the same codebehind file for a certain
page which is translated into different languages. In this way I only need to
change to aspx-file (html) of the page for each new language I want to
support, and all my codebehind logic will centralized to one place.

Example:

I have one original page in english called 'Page1_eng.aspx' which has a
corresponding 'Page1.cs'. Now if I want to have this page translated to
swedish I will create a new page called 'Page1_swe.aspx' which uses the same
codebehind file ('Page1.cs'). Of course - this requires I have the same web
controls and ID's on the page.

I just wanted to see what you think about this idea? I have done some tests
and it seems to work perfect.

Thanks
Thomas
Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Another approach is to write everything in a base language then store the
text for each langauge translation in an external file / db and then at
runtime, read down the DOM replacing the base text with the translated text.

We went a bit further and wrote controls to do the lookup and translation
for us, so all we had to do was put the control on the page and set the
english text.. when the browser language came back as different, it would
auto-translate the text to the new langauge.by finding the translation in
the DB.

HTH
Adrian Parker
Ingenuity At Work Ltd

"Thomas Andersson" <1q****************@newsgroup.nospam> wrote in message
news:79**********************************@microsof t.com...
Hi all,

I've been thinking of about adding new languages to our website and is
currently investigating how this could be done. And I know that one way to
go
would be to create new aspx-pages with new codebehinds for each page I
want
to have translated.

But my question is - is it ok to keep the same codebehind file for a
certain
page which is translated into different languages. In this way I only need
to
change to aspx-file (html) of the page for each new language I want to
support, and all my codebehind logic will centralized to one place.

Example:

I have one original page in english called 'Page1_eng.aspx' which has a
corresponding 'Page1.cs'. Now if I want to have this page translated to
swedish I will create a new page called 'Page1_swe.aspx' which uses the
same
codebehind file ('Page1.cs'). Of course - this requires I have the same
web
controls and ID's on the page.

I just wanted to see what you think about this idea? I have done some
tests
and it seems to work perfect.

Thanks
Thomas

Nov 19 '05 #2

P: n/a
That's NOT a very good way to go when it comes to language support!

you should use the same page for all languages there are many ways to go
when it comes to this.

Either you can use a Database (which most people do), Access or SQL server
or something but if you don't have that you can use XML files, text files,
Resource Files... whatever to store the different language texts in.

Just have some kind of ID for the texts and refer to them and then use a
sessionbased "langugecode" to select the right one...

or was the question not about this?

/Lars Netzel
"Thomas Andersson" <1q****************@newsgroup.nospam> skrev i meddelandet
news:79**********************************@microsof t.com...
Hi all,

I've been thinking of about adding new languages to our website and is
currently investigating how this could be done. And I know that one way to
go
would be to create new aspx-pages with new codebehinds for each page I
want
to have translated.

But my question is - is it ok to keep the same codebehind file for a
certain
page which is translated into different languages. In this way I only need
to
change to aspx-file (html) of the page for each new language I want to
support, and all my codebehind logic will centralized to one place.

Example:

I have one original page in english called 'Page1_eng.aspx' which has a
corresponding 'Page1.cs'. Now if I want to have this page translated to
swedish I will create a new page called 'Page1_swe.aspx' which uses the
same
codebehind file ('Page1.cs'). Of course - this requires I have the same
web
controls and ID's on the page.

I just wanted to see what you think about this idea? I have done some
tests
and it seems to work perfect.

Thanks
Thomas

Nov 19 '05 #3

P: n/a
And you'll have to maintain a separate page for each language.

It looks like you translate pages manually. Instead you could use resources
(see the ASP.NET). In 2.0, you can even use natively a DB and you have also
design time support for localization...

Patrice

--

"Thomas Andersson" <1q****************@newsgroup.nospam> a écrit dans le
message de news:79**********************************@microsof t.com...
Hi all,

I've been thinking of about adding new languages to our website and is
currently investigating how this could be done. And I know that one way to go would be to create new aspx-pages with new codebehinds for each page I want to have translated.

But my question is - is it ok to keep the same codebehind file for a certain page which is translated into different languages. In this way I only need to change to aspx-file (html) of the page for each new language I want to
support, and all my codebehind logic will centralized to one place.

Example:

I have one original page in english called 'Page1_eng.aspx' which has a
corresponding 'Page1.cs'. Now if I want to have this page translated to
swedish I will create a new page called 'Page1_swe.aspx' which uses the same codebehind file ('Page1.cs'). Of course - this requires I have the same web controls and ID's on the page.

I just wanted to see what you think about this idea? I have done some tests and it seems to work perfect.

Thanks
Thomas

Nov 19 '05 #4

P: n/a
Thanks Adrian, Lars & Patrice for fast replies!

I like the idea of what you are describing. The only thing I am thinking of
is that I have a few pages with a lot of images (with text on them), but of
course I could change the URL for these images depending on a
session[languageid].

By the way where do you check for your session[languageid]? In Page_Load
event?

Are there any good reasons why you should store your translated text in
resource files instead of a db?

Thanks
Thomas
Nov 19 '05 #5

P: n/a
A Resource File ( as they speak of them in .NET terms) will need to be
recompiled if you want to add more texts to it.
In database you just need to add things... but you need a licence probably
/Lars

"Thomas Andersson" <1q****************@newsgroup.nospam> skrev i meddelandet
news:C3**********************************@microsof t.com...
Thanks Adrian, Lars & Patrice for fast replies!

I like the idea of what you are describing. The only thing I am thinking
of
is that I have a few pages with a lot of images (with text on them), but
of
course I could change the URL for these images depending on a
session[languageid].

By the way where do you check for your session[languageid]? In Page_Load
event?

Are there any good reasons why you should store your translated text in
resource files instead of a db?

Thanks
Thomas

Nov 19 '05 #6

P: n/a
Thanks for everybody's informative inputs.

Hi Thomas,

First, I can also confirm that we can reuse asp.net page's codebehind file
for multi aspx pages. In fact, the codebehind file(page class) are all
compiled into assemblies. So the one we reuse is the page class in the
assembly rather than the codebehind file.(Codebehind is used for VS.NET at
design-time)

Also, as other members have said, we are more recommeded to make use of the
.net application's buildin globalization/localization features rather than
provide multi pages for different cultures. As for the two new questions
you mentioned, here is some of my understandings:

========================
By the way where do you check for your session[languageid]? In Page_Load
event?
=======================
In asp.net , the Request object has a UserLanguages collection which
contains the client browser's favored languages and we can use the
CultureInfo class under the System.Globalization namespace to create a
CultureInfo instance through one of the language item, for example:

#setting the current thread's culture info
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(Request.UserLang uages[0]);

#Using the CurrentCulture Property
http://msdn.microsoft.com/library/en...gcurrentcultur
eproperty.asp?frame=true

Thus, we can put the above code in your asp.net web application's global
object's BeginRequest event, such as :

protected void Application_BeginRequest(Object sender, EventArgs e)
{
System.Web.HttpApplication app = sender as System.Web.HttpApplication;
System.Web.HttpRequest req = app.Request;

System.Globalization.CultureInfo ci =
System.Globalization.CultureInfo.CreateSpecificCul ture(req.UserLanguages[0])
;
System.Threading.Thread.CurrentThread.CurrentCultu re = ci;
}
then, in each page's Load or Init event, you can retrieve the current
thread's culture info and retrieve the correct localized resources to
decorate your page UI
=======================
Are there any good reasons why you should store your translated text in
resource files instead of a db?
=========================

use resources files can help use embeded the resource into assembly so that
we can put different resources (for different culture) in different
assemlblies which are located in a hierarchical structure in the
application's bin folde such as
/bin
mainresource.dll
/en-US
/zh-CN
/fr-FR

Also, the asp.net application provide shadow copy for the assemblies it
use, so that we can update the assemly whenever we have new versions. I
think this is much flexible than use DB storage.

Just some of my opinions. Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.