Connecting Tech Pros Worldwide Forums | Help | Site Map

Print address in country specific format

Newbie
 
Join Date: Jul 2009
Posts: 3
#1: Jul 2 '09
Hello,
I have a problem. I have a email stored in database in fields (e.g. AddressLine1, Postal Code, Zip .. e.t.c.) I need a solution to display address to user in selected country format. It does't matter online service or offline dll. It doesn't matter free or paid service. Please, help

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#2: Jul 2 '09

re: Print address in country specific format


What???

An Email address identifies a location to which e-mail messages can be delivered. Email addresses are formatted so that they can be used on the Internet to specify where the email should be sent to.

Email addresses have nothing to do with countries or cultures.

I think you're going to be interested in researching the topic of ASP.NET Globalization. You can use globalization to format web pages according to the user's cultural selection.

-Frinny
Newbie
 
Join Date: Jul 2009
Posts: 3
#3: Jul 3 '09

re: Print address in country specific format


Sorry, there must be country-neutral address , NOT email... Sorry.
ASp.NET GLobaliztion doesn't solve this problem.

AS example i have a address stored in DB in fields (ZipCode, AddressLine1, AddressLine2 e.t.c. )
My user from US so he see address in this format:
AddressLine1
City State ZIP

If He is from Russia:

Postal Code
Country,
City,
Region.
Street
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#4: Jul 3 '09

re: Print address in country specific format


This is a perfect example of where you would use globalization.

You have a bunch of prompts that correspond to some inputs that let the user enter their street address. If they live in a different country the prompts are different for the inputs...but the inputs still pretty much represent the same thing.

What you'll need to do is create resources (typically resx files) for each culture & country that you want to support. When the browser detects this country/culture, or when the user specifies their country/culture, ASP.NET will automatically load the correct resource for the page. Unless you're using global resources, where you'll have to fetch using a ResourceManager, but it's not that hard to implement.

Please research Globalization. If you run into any problems implementing it, give a shout and we'll help you out :)


If you need to re-arrange the elements (prompts & inputs) all you have to do is check the user's cultural settings and apply a CSS style to move the elements around.

-Frinny
Newbie
 
Join Date: Jul 2009
Posts: 3
#5: Jul 3 '09

re: Print address in country specific format


Sorry for silly question. But how globalization could help me format address output?

Using resource I could localizate labels , text e.t.c. But how i can do with address formatting?
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#6: Jul 3 '09

re: Print address in country specific format


It's not a silly question at all.

You can dynamically specify which CSS pages are used in the page according to the user's culture. I'm sure you could store the CSS in your resx files that you are using for localization, but I haven't really played with that much so I'm going to suggest dynamically including CSS file....

Let me start at the beginning :)

First of all you'll have to arrange your prompt/input elements into groups so that you can change their position using CSS.

Then you'll have to write a CSS file for each culture that you're supporting. Make sure that the class/element names in the CSS files properly match with the prompt/input element groups you're using....these names should be the same for every CSS file that you're using.

Now, all you have to do is add the appropriate CSS file to the project according to the user's culture. You can check the user's culture using the Thread.CurrentThread.CurrentCulture or Thread.CurrentThread.CurrentUICulture property.

With this you can determine what CSS file to use...and add the appropriate CSS file:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ApplyStyle()
  2.   Dim sytleSheet As New HtmlGenericControl("link")
  3.   styleSheet.Attributes.Add("type", "text/css")
  4.   styleSheet.Attributes.Add("rel", "stylesheet")
  5.  
  6.    Select Case usersCulture
  7.        Case "en-US"
  8.           styleSheet.Attributes.Add("href","URL To English US style sheet")
  9.        .....
  10.    end select
  11.  
  12.   Me.Page.Header.Controls.Add(styleSheet)
  13. End Sub

If CSS is too hard to use, you can consider dynamically adding elements to your page instead of defining them in your ASPX code. This requires a lot more knowledge of the ASP lifecycle and how dynamic elements work...

Let me know if the CSS solution doesn't work for you...and then I'll help you through the dynamic controls solution.
Reply


Similar ASP.NET bytes