【问题标题】:What is a basepage, and if I don't have one, can I create on in Visual Studio 2010?什么是基本页面,如果我没有,我可以在 Visual Studio 2010 中创建吗?
【发布时间】:2012-01-23 08:29:06
【问题描述】:

为了让客户手动选择他们自己的语言,我收到了在我的“基本页面”中安装以下内容的说明。我只有普通的 .aspx 页面和 5 个母版页。我有一个 Visual Studio 2010 / vb / net 4.0 网站。我刚刚在 Visual Studio 中创建了自己的类,并将 BasePage.vb 放在我的 app_code 文件夹中。我做的对吗?

  Public Class BasePage
Inherits Page
Private Const m_DefaultCulture As String = "en-GB"

Protected Overrides Sub InitializeCulture()
    'retrieve culture information from session
    Dim culture__1 As String = Convert.ToString(Session("MyCulture"))

    'check whether a culture is stored in the session
    If Not String.IsNullOrEmpty(culture__1) Then
        Culture = culture__1
    Else
        Culture = m_DefaultCulture
    End If

    'set culture to current thread
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture__1)
    Thread.CurrentThread.CurrentUICulture = New CultureInfo(culture__1)

    'call base class
    MyBase.InitializeCulture()
End Sub
End Class

【问题讨论】:

  • 请在SO提出您的其他问题

标签: asp.net visual-studio visual-studio-2010 master-pages


【解决方案1】:

只需创建一个名为 BasePage 的类,并从该页面而不是经典的 ASP.NET 页面派生所有页面。

您的 BasePage 将派生自经典的 ASP.NET 页面。

阅读Using a Custom Base Class for your ASP.NET Pages' Code-Behind Classes

【讨论】:

  • 谢谢哈桑!感谢您的回复!我只是做了你让我做的事——我创建了一个类。现在我必须在 homepage.master 或 homepage.master.vb 文件的顶部放一些东西吗?像 Inherits="BasePage"??再次感谢!
  • @JasonWeber 您项目中的每个页面都必须已经从 System.Web.UI.Page 派生,只需将其替换为您的类的名称。确保您的自定义基础确实继承自 UI.Page
  • 好的 -- 非常感谢你的帮助,Hasan -- 我将把 system.web.ui.page 替换为 basepage。再次感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-03
  • 2011-11-05
  • 2018-02-19
  • 1970-01-01
  • 2017-04-10
相关资源
最近更新 更多