2011-02-11 72 views
0

在我們的.aspx頁,我們有很多這樣的代碼:VB.NET:擴展方法頁面使用GetLocalResourceObject

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

我想補充一點,我可以使用擴展方法我們的.aspx的意見,讓我做這件事:

<%= 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 

根據智能感知,在PROBL em是GetLocalResourceObject不作爲System.Web.UI.TemplateControl對象的方法存在。

但是,當我看着this page MSDN上,它的存在。

我在做什麼錯?擴展方法應該放在不同的對象上嗎?我試過其他人,並且具有相同的Intellisense /構建錯誤。

+0

這是一個`protected`方法。 – SLaks 2011-02-11 21:29:31

回答

0

GetLocalResourceObject是受保護的,因此只能從網頁內調用。

我發佈了一個類似的問題,看看是否有人知道如何在頁面外打電話。

我試圖創建繼承頁面對象的類,然後暴露調用GetLocalResourceObject內部方法。我無法得到它的工作,因爲當你通過ME /這不是引用一個頁面對象。

這是我類似的問題: Is there a way to move a call to ASP GetLocalResourceObject to a external static/shared method?