【问题标题】:Calling a shared procedure from a module从模块调用共享过程
【发布时间】:2011-08-06 15:48:22
【问题描述】:

我很想在一个模块中使用以下过程来设置我的页面的标题、关键字等。

  Public Shared Sub SetTitle(ByVal Heading As String, ByVal Keywords As String())
        Dim myMaster As Masterpage = DirectCast(Me.Master, Masterpage)
        If Request.QueryString("lng") = "es" Then
            myMaster.MasterHeading = Heading
            myMaster.MetaTitle = Heading
            myMaster.MetaDescription = ""
            myMaster.MetaKeywords = GetKeywords(Keywords)
        End If
        myMaster.MetaTitle = myMaster.MasterHeading
    End Sub

问题是我得到了两个错误。

Me.Master 我得到'Me' is valid only within an instance method. 错误并且在

If Request...我得到错误

Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.

那么我该如何解决这些问题?我希望将这个程序放在一个共同的地方,而不是在每个页面中。

提前谢谢你。

【问题讨论】:

    标签: asp.net vb.net module master-pages


    【解决方案1】:

    如果将此函数移至模块,则不需要shared 关键字,因为模块中的函数是有效共享的。 See this answer.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 2012-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-08
      相关资源
      最近更新 更多