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: <
[email protected]>
| From: Brock Allen <
[email protected]>
| Subject: Re: custom resource manager in ASP.NET 2.0
| References: <
[email protected]>
| 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!TK2MSFTNGP11.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.AppSettings[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
|
|
|