ASP.NET 2.0: 如何实现按一个按键在两种语言之间切换

发表于:2007-07-01来源:作者:点击数: 标签:
我要实现这样一个功能,就是按一个按键在两种语言(比如中文和英文)之间切换。 注:我用的是ASP.NET Beta 2。参考文章列在最后。 参考第一篇文章,"Implicit Localization Expressions"一节。一个页面(Page)的 本地化 内容是在FrameworkInitlize()中创建所
我要实现这样一个功能,就是按一个按键在两种语言(比如中文和英文)之间切换。

注:我用的是ASP.NET Beta 2。参考文章列在最后。

参考第一篇文章,"Implicit Localization Expressions"一节。一个页面(Page)的本地化内容是在FrameworkInitlize()中创建所有的控件时决定的。比如

   button1.Text = ((string)
      base.GetLocalResourceObject("LinkButtonResource1.Text"));

所以要在FrameworkInitlize()之前设置好你所需要的页面的文化(Culture).

第二篇文章"Page Lifecycle"一节列出了页面的生命周期(Lifecycle)涉及的方法。下面列出了从页面的构造函数(Constructor)开始与我的问题相关的一些方法。

    Constructor
    Construct
    TestDeviceFilter
    AddParsedSubObject
    DeterminePostBackMode
    OnPreInit
    LoadPersonalizationData
    InitializeThemes
    OnInit

在第三篇文章"The Page Lifecycle"的开头写道:

Once the HTTP page handler class is fully identified, the ASP.NET run time calls the handler@#s ProcessRequest method to process the request. ... (it) begins by calling the method FrameworkInitialize, which builds the controls tree for the page. The method is a protected and virtual member of the TemplateControl class - the class from which Page itself derives. Any dynamically generated handler for an .aspx resource overrides FrameworkInitialize. In this method, the whole control tree for the page is built.

Next, ProcessRequest makes the page transit various phases: initialization, loading of view state information and postback data, loading of the page@#s user code and execution of postback server-side events. After that, the page enters in rendering mode: the updated view state is collected; the HTML code is generated and then sent to the output console. Finally, the page is unloaded and the request is considered completely served.

从这里,我推断FrameworkInitlize()至少是在OnPreInit()之前被调用的。但是仍然看不出来FrameworkInitlize的准确位置。

绕过上面所说的这些。有两种方法可以实现上述的要求。

方法一。在某页面的InitializeCulture方法中设置你所需要的文化。比如

原文转自:http://www.ltesting.net