Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 5th, 2007, 02:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default auto culture for code in App_Code

Hi all.

I'm doing my first crack at localization and found it fairly easy but for some reason it doesn't effect code in the App_Code folder. I have a helper class that fills in months into a DropDownList like so:
Code:
public void PopulateWithMonths(DropDownList ddlcontrol, bool selectcurrent)
    {
        DateTime month = new DateTime(DateTime.Today.Year, 1, 1);
        for (int i = 0; i < 12; i++)
        {
            DateTime NextMont = month.AddMonths(i);
            ListItem item = new ListItem();
            item.Text = NextMont.ToString("MMM") + " - " + NextMont.AddMonths(5).ToString("MMM");
            item.Value = NextMont.Month.ToString();
            ddlcontrol.Items.Add(item);
        }
        if (selectcurrent == true)
        {
            ddlcontrol.Items.FindByValue(DateTime.Today.Month.ToString()).Selected = true;
        }
    }

Where can I change this behavior?

Thanks in advance!

 - mega
Moving to C# .NET
__________________
- mega
Aspiring JavaScript Ninja
 
Old January 5th, 2007, 02:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

Doesn't matter I figured it out. Here is the code:
Code:
 public void PopulateWithMonths(DropDownList ddlcontrol, bool selectcurrent)
    {
        GregorianCalendar culture = new GregorianCalendar(GregorianCalendarTypes.Localized);
        DateTime month = new DateTime(DateTime.Today.Year, 1, 1, culture);
        for (int i = 0; i < 12; i++)
        {
            DateTime NextMont = month.AddMonths(i);
            ListItem item = new ListItem();
            item.Text = NextMont.ToString("MMM") + " - " + NextMont.AddMonths(5).ToString("MMM");
            item.Value = NextMont.Month.ToString();
            ddlcontrol.Items.Add(item);
        }
        if (selectcurrent == true)
        {
            ddlcontrol.Items.FindByValue(DateTime.Today.Month.ToString()).Selected = true;
        }
    }


 - mega
Moving to C# .NET
 
Old January 9th, 2007, 05:59 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well I have a similar problem, I have created a web application that deals much with dates, and I debugged it, and it was perfect.
When I published the page, the dates switched into the Arabic format!
I checked the regional setting, and the default was English, I added the culture into the web.config. But still same problem!

So any suggestions?



 
Old January 12th, 2007, 03:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

Hi zaghmout.

First make sure that your page declaration (or define it in web.config) is
Code:
<%@ Page Culture="auto" UICulture="auto" %>
That ensures that the culture that the browser is using is the one ASP.NET is responding to (you can also specify a culture if you want).
Second look at how your browser is configured. If you use IE6 it's: Tools -> Internet settings -> the general tab and then click the Language button. The highest ranking language is the one the browser sends to the web server. If FF: Tools -> Settings -> the general tab and then click the "Choose..." button in the Language fieldset. The same language rule applies to both browsers.
Hope this helps!

 - mega
Moving to C# .NET
 
Old January 14th, 2007, 04:59 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot mega,

You really cannot imagine how much help that was :)

And yeap it did work :)

 
Old April 5th, 2007, 05:06 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Default

while I was working, I had some crystal reports which contains date too, and I noticed that it does not take the date format neither from the IIS, nor from the web.config, nor even from the regional settings! I really don't know how exactly it decided the date format, and that was a real problem :) so for whom who have this problem you should ALWAY customize the date in the crystal reports :) unless there were something I'm missing here :)

Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"





Similar Threads
Thread Thread Starter Forum Replies Last Post
App_Code and User Control rolandatem ASP.NET 2.0 Basics 0 April 2nd, 2007 05:42 PM
culture info !! angelboy C# 2005 2 March 14th, 2007 12:18 AM
Browser RSS feed auto detection code here madok BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 September 29th, 2006 09:04 AM
Renaming App_Code jacob .NET Web Services 5 July 4th, 2006 12:20 AM
Identify culture(of the client) from web request a madkaikar_ashish General .NET 2 February 2nd, 2005 01:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.