有没有办法将调用 ASP GetLocalResourceObject 移动到外部静态/共享方法? [英] Is there a way to move a call to ASP GetLocalResourceObject to a external static/shared method?

查看:52
本文介绍了有没有办法将调用 ASP GetLocalResourceObject 移动到外部静态/共享方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ASP 中使用本地资源字符串.我的字符串类似于 "This is a {0}"我正在使用 String.Format 来替换 {0} 值.

I am using local resource strings in ASP. My strings are something like "This is a {0}" I am using String.Format to replace the {0} value.

无论如何,我想创建一个任何页面都可以调用的静态/共享方法,而不是将这段代码放在每个页面中.我以为我可以传入页面并调用 GetLocalResourceObject() 方法.GetLocalResourceObject() 受保护,因此无效.

In anycase, rather the put this code in every page, I wanted to create a Static/Shared method that any page could call. I had thought that I could pass the page in and call the GetLocalResourceObject() method. GetLocalResourceObject() is protected so its not valid.

有没有办法在代码隐藏的外部调用它?

Is there a way to call this external to the code-behind?

Shared Function GetPatternedResourceString(Byval P as Page, ByVal key As String, ByVal replacement As String) As String

        Return String.Format(p.GetLocalResourceObject(key), replacement)

    End Function

我意识到还有其他一些方法可以获取本地资源,我认为 HttpContext 上有一种方法,但是您需要做一些额外的工作并传入 url 路径等.

I realize there are some other ways to get a local resource, I think there is one on HttpContext but you need to do some extra work and pass in url paths, etc.

这实际上与此处列出的问题相同VB.NET:使用 GetLocalResourceObject 的页面的扩展方法

This is actually the same problem listed here VB.NET: Extension method for pages that uses GetLocalResourceObject

推荐答案

GetLocalResourceObject() - 根据指定的 VirtualPath 和 ResourceKey 属性获取页面级资源对象.如需更多说明,您应该阅读 this

GetLocalResourceObject() - Gets a page-level resource object based on the specified VirtualPath and ResourceKey properties. For more clarification you should read this

这篇关于有没有办法将调用 ASP GetLocalResourceObject 移动到外部静态/共享方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆