By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

custom resource manager in ASP.NET 2.0

P: n/a
Hi,

is it possible to implement custom resource managers for ASP.NET 2.0 so
that strings can be read from a database (for example)?

Ideally, it should be possible to configure the custom resource manager
in web.config, so that it replaces the default resource manager. Using
the <%$ ... %> syntax should read the strings via the custom resource
manager, e.g. when used like this:
<asp:Label ID="Label1" runat="server"
Text="<%$ Resources:Resource, STRING_ID %>"></asp:Label>
Thanks for any help,
Martin
Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Martin,

I have done this in one of my project. I created an extended resource
manager which gets the strings file from the xml rather getting it from the
compiled resource, so it is possible, that you can extend the asp.net
resource manager according to your requirement.

--
Wajahat Abbas
http://www.dotnetpakistan.com
http://www.wajahatabbas.com
"Martin Bischoff" wrote:
Hi,

is it possible to implement custom resource managers for ASP.NET 2.0 so
that strings can be read from a database (for example)?

Ideally, it should be possible to configure the custom resource manager
in web.config, so that it replaces the default resource manager. Using
the <%$ ... %> syntax should read the strings via the custom resource
manager, e.g. when used like this:
<asp:Label ID="Label1" runat="server"
Text="<%$ Resources:Resource, STRING_ID %>"></asp:Label>
Thanks for any help,
Martin

Nov 19 '05 #2

P: n/a
Hi Martin,

Welcome to ASP.NET newsgroup.
Regarding on the asp.net 2.0 resource manager question you mentioned,
based on my understanding, this is not available in the comming 2.0 versino
of the ASP.NET. Since the <%$ %> expression are translated to the actual
code/statements at compile time, this translation is fixed in the compiler,
we won't be able to customize it with our own type. Currently I think we
may consider use the <%# %> databinding experssion with out own custom
class or function to retrieve the resource as we like.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Date: Wed, 31 Aug 2005 09:19:53 +0200
| From: Martin Bischoff <ni******@newsgroup.nospam>
| User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
| X-Accept-Language: en-us, en
| MIME-Version: 1.0
| Subject: custom resource manager in ASP.NET 2.0
| Content-Type: text/plain; charset=ISO-8859-1; format=flowed
| Content-Transfer-Encoding: 7bit
| Message-ID: <OP**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 194.209.202.1
| Lines: 1
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:121351
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi,
|
| is it possible to implement custom resource managers for ASP.NET 2.0 so
| that strings can be read from a database (for example)?
|
| Ideally, it should be possible to configure the custom resource manager
| in web.config, so that it replaces the default resource manager. Using
| the <%$ ... %> syntax should read the strings via the custom resource
| manager, e.g. when used like this:
|
|
| <asp:Label ID="Label1" runat="server"
| Text="<%$ Resources:Resource, STRING_ID %>"></asp:Label>
|
|
| Thanks for any help,
| Martin
|

Nov 19 '05 #3

P: n/a
Yes, these can be customized. They're called expression builders. I posted
in the past month an example, but here's another:

using System.Web.Compilation;
using System.CodeDom;

public class AppSettExBld : ExpressionBuilder
{
public static string GetVal(string param)
{
return System.Web.Configuration.WebConfigurationManager.A ppSettings[param];
}
public override System.CodeDom.CodeExpression GetCodeExpression(BoundPropertyEntry
entry, object parsedData, ExpressionBuilderContext context)
{
CodeMethodInvokeExpression ex = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(AppSettExBld)),
"GetVal", new CodePrimitiveExpression(entry.Expression.ToString( ).Trim()));
return ex;
}
}
The method you should customize is GetVal. This sample simply reads from
<appSettings> but you could read from a database. To configure you need to
modify the <compilation> section in web.config:

<compilation debug="true" defaultLanguage="C#">
<expressionBuilders>
<add expressionPrefix="AppSet" type="AppSettExBld, __code"/>
</expressionBuilders>
</compilation>
And now you can use <%$ AppSett:SomeKeyToTheGetValMethod %> in your ASPX
pages.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

is it possible to implement custom resource managers for ASP.NET 2.0
so that strings can be read from a database (for example)?

Ideally, it should be possible to configure the custom resource
manager in web.config, so that it replaces the default resource
manager. Using the <%$ ... %> syntax should read the strings via the
custom resource manager, e.g. when used like this:

<asp:Label ID="Label1" runat="server"
Text="<%$ Resources:Resource, STRING_ID %>"></asp:Label>
Thanks for any help,
Martin


Nov 19 '05 #4

P: n/a
Thanks a lot for both Wajahat and Brock's informative suggestions.

Seems I've really missed such a great feature. I'll keep this in mind and
have some further investigate in the
asp.ne whidbey.

Thanks again for your contribution.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Message-ID: <11***********************@msnews.microsoft.com>
| From: Brock Allen <ba****@NOSPAMdevelop.com>
| Subject: Re: custom resource manager in ASP.NET 2.0
| References: <OP**************@TK2MSFTNGP09.phx.gbl>
| Mime-Version: 1.0
| Content-Transfer-Encoding: 8bit
| Content-Type: text/plain; charset=iso-8859-1; format=flowed
| X-Newsreader: JetBrains Omea Reader 469.1
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Date: Wed, 31 Aug 2005 21:19:41 -0700
| NNTP-Posting-Host: 12.162.27.25
| Lines: 1
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP11.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:121612
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Yes, these can be customized. They're called expression builders. I
posted
| in the past month an example, but here's another:
|
| using System.Web.Compilation;
| using System.CodeDom;
|
| public class AppSettExBld : ExpressionBuilder
| {
| public static string GetVal(string param)
| {
| return
System.Web.Configuration.WebConfigurationManager.A ppSettings[param];
| }
| public override System.CodeDom.CodeExpression
GetCodeExpression(BoundPropertyEntry
| entry, object parsedData, ExpressionBuilderContext context)
| {
| CodeMethodInvokeExpression ex = new CodeMethodInvokeExpression(new
CodeTypeReferenceExpression(typeof(AppSettExBld)),
| "GetVal", new
CodePrimitiveExpression(entry.Expression.ToString( ).Trim()));
| return ex;
| }
| }
|
|
| The method you should customize is GetVal. This sample simply reads from
| <appSettings> but you could read from a database. To configure you need
to
| modify the <compilation> section in web.config:
|
| <compilation debug="true" defaultLanguage="C#">
| <expressionBuilders>
| <add expressionPrefix="AppSet" type="AppSettExBld, __code"/>
| </expressionBuilders>
| </compilation>
|
|
| And now you can use <%$ AppSett:SomeKeyToTheGetValMethod %> in your ASPX
| pages.
|
| -Brock
| DevelopMentor
| http://staff.develop.com/ballen
|
|
|
| > Hi,
| >
| > is it possible to implement custom resource managers for ASP.NET 2.0
| > so that strings can be read from a database (for example)?
| >
| > Ideally, it should be possible to configure the custom resource
| > manager in web.config, so that it replaces the default resource
| > manager. Using the <%$ ... %> syntax should read the strings via the
| > custom resource manager, e.g. when used like this:
| >
| > <asp:Label ID="Label1" runat="server"
| > Text="<%$ Resources:Resource, STRING_ID %>"></asp:Label>
| > Thanks for any help,
| > Martin
|

|
|

Nov 19 '05 #5

P: n/a
Thanks to everyone. In the meantime I have also found out about expression
builders, and these allow me to do what I want.

I have also read about ResourceProviderFactory, IResourceProvider and
IResourceReader. But I did not find a way to configure ASP.NET to use my
custom resource manager instead of the default one (at least for strings).

Regards,
Martin

Brock Allen wrote:
Yes, these can be customized. They're called expression builders. I
posted in the past month an example, but here's another:

using System.Web.Compilation;
using System.CodeDom;

public class AppSettExBld : ExpressionBuilder
{
public static string GetVal(string param)
{
return
System.Web.Configuration.WebConfigurationManager.A ppSettings[param];
}
public override System.CodeDom.CodeExpression
GetCodeExpression(BoundPropertyEntry entry, object parsedData,
ExpressionBuilderContext context)
{
CodeMethodInvokeExpression ex = new
CodeMethodInvokeExpression(new
CodeTypeReferenceExpression(typeof(AppSettExBld)), "GetVal", new
CodePrimitiveExpression(entry.Expression.ToString( ).Trim()));
return ex;
}
}
The method you should customize is GetVal. This sample simply reads from
<appSettings> but you could read from a database. To configure you need
to modify the <compilation> section in web.config:

<compilation debug="true" defaultLanguage="C#">
<expressionBuilders>
<add expressionPrefix="AppSet" type="AppSettExBld,
__code"/>
</expressionBuilders>
</compilation>
And now you can use <%$ AppSett:SomeKeyToTheGetValMethod %> in your ASPX
pages.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

is it possible to implement custom resource managers for ASP.NET 2.0
so that strings can be read from a database (for example)?

Ideally, it should be possible to configure the custom resource
manager in web.config, so that it replaces the default resource
manager. Using the <%$ ... %> syntax should read the strings via the
custom resource manager, e.g. when used like this:

<asp:Label ID="Label1" runat="server"
Text="<%$ Resources:Resource, STRING_ID %>"></asp:Label>
Thanks for any help,
Martin


Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.