GetLocalResourceObject

GetLocalResourceObject

本文介绍了VB.NET:使用GetLocalResourceObject的页面的扩展方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的.aspx页面中,我们有很多这样的代码:

In our .aspx pages, we've got lots of this code:

<%= CType(GetLocalResourceObject("key"), String)) %>

我想添加一个扩展方法,我可以在.aspx视图中使用该扩展方法,使我能够做到这一点:

I'd like to add an extension method that I can use in our .aspx views that allows me to do this:

<%= GetLocalResourceString("key") %>

代码无法正常工作,

Imports System.Runtime.CompilerServices
Imports System.Web.UI

Module Extensions

    <Extension()> 
    Public Function GetLocalResourceString(ByVal control as TemplateControl, 
        ByVal resourceKey as String) as String
        Return CType(control.GetLocalResourceObject(resourceKey)), String)
    End Sub

End Module

根据Intellisense,问题在于GetLocalResourceObject作为System.Web.UI.TemplateControl对象的方法不存在.

According to Intellisense, the problem is that GetLocalResourceObject doesn't exist as a method of System.Web.UI.TemplateControl objects.

但是,当我在MSDN上查看此页面时,它是在那里.

However, when I look at this page on MSDN, it's there.

我做错了什么?扩展方法应该在其他对象上吗?我试过其他人,并且遇到相同的Intellisense/build错误.

What am I doing wrong? Should the extension method be on a different object? I've tried others and have the same Intellisense/build error.

推荐答案

GetLocalResourceObject受保护,因此只能从页面内部调用.

GetLocalResourceObject is protected so it can only be called from inside the page.

我发布了一个类似的问题,以查看是否有人知道如何在页面外拨打电话.

I posted a similar question to see if anyone knew how to call outside the page.

我尝试创建一个继承Page对象的类,然后在内部公开一个名为GetLocalResourceObject的方法.我无法使它正常工作,因为当您通过ME/此操作时,您没有引用Page对象.

I tried creating a class that inherited the Page object and then exposing a method that called GetLocalResourceObject internally. I couldnt get it to work because when you pass ME/This you are not referencing a Page object.

这是我的类似问题:存在一种将对ASP GetLocalResourceObject的调用移至外部静态/共享方法的方法?

Here is my similar Question:Is there a way to move a call to ASP GetLocalResourceObject to a external static/shared method?

这篇关于VB.NET:使用GetLocalResourceObject的页面的扩展方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 02:16