2011-08-06 56 views
0

我希望使用以下過程在模塊中設置頁面的標題,關鍵字等。從模塊調用共享過程

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.

那麼如何解決這些?我希望在一個共同的地方,而不是在每一頁都有這個程序。

預先感謝您。

回答

0

如果您將此功能移動到某個模塊,那麼您不需要shared關鍵字作爲模塊中的功能被有效共享。 See this answer