0

I would love to use the following procedure to set the Title, keywords etc. of my pages, in a module.

  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

The problem is that i get two errors.

At Me.Master i get the 'Me' is valid only within an instance method. error and at

If Request... i get the error

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.

So how do i fix these? I would like to have that procedure in a common place and not in every page.

Thank you in advance.

OrElse
  • 9,709
  • 39
  • 140
  • 253

1 Answers1

0

If you move this function to a module then you do not need the shared keyword as functions in a module are effectively shared. See this answer.

Community
  • 1
  • 1
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143