ASP.NET网页全球化和放大器;本地化母版页C#3.0 [英] ASP.NET Web Page Globalization & Localization in Master Page C# 3.0

查看:103
本文介绍了ASP.NET网页全球化和放大器;本地化母版页C#3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能使用在母版页以下code全球化和放大器;本土化。它使误差在code部分评论说:不包含认定中的InitializeCulture

I cant use the following code in Master page for Globalization & Localization. It gives the error as commented in the code part "does not contain a defination for InitializeCulture"

   protected override void InitializeCulture()
    {
        if (Request["Language"] != null)
        {
            //String selectedLanguage = Request["Language"];
           // code wil go here

        }
        base.InitializeCulture();
       //base.InitializeCulture gives error as mentioned in the next line
       //does not contain a defination for InitializeCulture
    }

在我这个code加比母版页等其他网页正常工作。有没有在母版页中使用此code任何限制。

When i add this code to other pages other than Master Page it works fine. is there any restriction on using this code in Master Page.

如果我能够定义母版页这code,那么我不需要写这篇code中的每个文件。

If i am able to define this code in Master Page then i dont need to write this code in every file.

我做得不对,我有包括线程和全球化文件,不过它不能在母版页的工作

Am i doing something wrong, I have include File for threading and Globalization, Still it doesn't work in Master Page

推荐答案

您必须这样做(=覆盖InitializeCulture)在你的Page类。它不会在母版页的工作(母版是从Control派生,而不是从页)。我建议你​​实现它是从页来源,从这个类派生每个web形式的基类,那么你也必须写code只有一次。它始终是方便有自己的基类。

You have to do this (= override InitializeCulture) in your Page class. It doesn't work in the master page (MasterPage is derived from Control, not from page). I would suggest that you implement a base class which is derived from Page and derive every web form from this class, then you also have to write the code only once. It is always handy to have your own base class.

在Visual Studio中添加一个新的类PageBase.cs:

In Visual Studio you add a new class PageBase.cs:

public class FormBase : Page
{
   protected override InitializeCulture()
   {
      if (Request.Form["lbCulture"] != null)
      {
         String selectedLanguage = Request.Form["lbCulture"];
         UICulture = selectedLanguage;
         Culture = selectedLanguage;

         Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage);
         Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);
      }
      base.InitializeCulture();
   }
}

目前的文化要么是存储在某些下拉列表框,在会话或查询字符串传递。我的示例中使用一个列表框。

The current culture is either stored in some dropdown listbox, in the session or passed by query string. I used a listbox in the sample.

然后你从该页面获得您的WebForm是这样的:

And then you derive your WebForm from this page like this:

public class Default : FormBase // instead of deriving from Page

这篇关于ASP.NET网页全球化和放大器;本地化母版页C#3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆