473,387 Members | 1,799 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,387 software developers and data experts.

Aspx-files sharing the same codebehind?

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
6 1999
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: rachel | last post by:
Hi all, I am new in ASP.Net. I have a question on link multiple web forms together. Here is the scenario: I create an Index.aspx WebForm which consists of a banner and three navigator...
11
by: Fred | last post by:
I have an aspx page: Main.aspx which has several components that cause a postback. In the page Main.aspx I also have an iframe which contains a multi-page pdf file. The problem I am facing is...
6
by: John Lau | last post by:
Hi, I am looking at the MS KB Article 306355: HOW TO: Create Custom Error Reporting Pages in ASP.NET by Using Visual C# .NET This article describes how to redirect errors to a custom html...
2
by: aspquest | last post by:
Hi All I have a web form page (page1.aspx) which has an iframe, and the src of the iframe is set to another web form page (page2.aspx). I would like to access the values of the server controls...
3
by: DavidS | last post by:
Have parent.aspx from which I open Driver.aspx form via button on parent.aspx. When I first open the modal dialog, the driver.aspx Page_Load function is called. After I close the dialog, then...
2
by: Janusz Jezowicz | last post by:
Hello! I would like to have one page on the server, which would be a target processing page for a number of other aspx pages. E.g Processing page \portal_page.aspx Target pages
24
by: John Rivers | last post by:
ASPX which means ASPX pages, the code-behind concept, User Controls, Web Controls etc. is very poorly designed and makes it extremely hard to develop professional quality web applications. ASPX...
13
by: Matt | last post by:
Does anyone know how to hide the ASPX extension of web pages in ASP.Net 2.0? Thanks, Matt
3
by: =?Utf-8?B?QXJ1bmVzaCBNb2hhbg==?= | last post by:
Hello All: I have an ASPX A.ASPX where I am displaying realtime data using embedded ASPX page B.ASPX. When I go to next page/previous page from A.ASPX page, I am able to go to next/previous...
0
JAMBAI
by: JAMBAI | last post by:
I have created a ASP.NET application and created two forms (Webform1.aspx & Webform2.aspx). I am displaying the Webform2.aspx based on the Webform1.aspx input, For example if the user didn't...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.