从模块调用共享过程
我很想使用以下过程在模块中设置我的页面的标题、关键字等。
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 inside an instance method.
错误,在
If Request...
我得到了错误
如果没有类的显式实例,则无法从共享方法或共享成员初始值设定项中引用类的实例成员。
那么我该如何修复这些问题呢?我希望将该过程放在一个公共位置,而不是每个页面。
先感谢您。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将此函数移至模块,则不需要
shared
关键字,因为模块中的函数已有效共享。 查看此答案。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.