Howto to use resources from System.Web?

G

Guest

I am using the ContentTemplate to extend the CreateUserWizard's
CreateUserWizardStep with additional controls. For the CreateUserWizardStep
labels, I would like to keep the automatic localization.
With Lutz Roeder's .Net Reflector, I found out that System.Web contains the
text resource System.Web.Resources and I found e.g. the name/value-pair
CreateUserWizard_DefaultUserNameLabelText=User Name:

My question here is: how can I bind this resource entry to the label?

I tried adding
Text="<%$ Resources:System.Web.resources,
CreateUserWizard_DefaultUserNameLabelText %>
to the asp:Label but I get the error message:
Parser error. The resource object with key
'CreateUserWizard_DefaultUserNameLabelText' was not found.


<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName"
Text="<%$ Resources:System.Web.resources,
CreateUserWizard_DefaultUserNameLabelText %>" /></td>


Any help would be greatly appreciated.
Dieter
 
S

Steven Cheng[MSFT]

Hello Dieter,

From your description, you're using the ContentTemplate to customize the
CreateUserWizard control and also want to utilize the existing localizaed
resources of the CreateuserWizard control. However, when you try using the
<%$ Resources:... %> expression to reference the resource, it not work,
correct?

As for this issue, it is due to the natural limitation of the <%$ Resource
%> expression, this expression just identical to the following methods in
page:

HttpContext.GetGlobalResourceObject Method

HttpContext.GetLocalResourceObject Method

Both of the two methods(also the <%$ Resource expression %>) can only
reference resource items defined within the current ASP.NET application's
LocalResource or GlobalResource, but can not reference resource items in
external assemblies. Actually, through the reflector diassembled code, you
can find that the built-in CreateUserWizard control is using the following
code to load resource string from assembly:

==================
ResourceManager rm = new ResourceManager("System.Web",
typeof(CreateUserWizard));

rm.GetString(keyname, Culture);

===================

Therefore, if you want to load any localization resource objects from
external assembly, you need to use ResourceManager to do it
programmatically.


Please feel free to let me know if you have anything unclear or any other
questions here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hello Steven,

thanks for the feedback!
ResourceManager rm = new ResourceManager("System.Web",
typeof(CreateUserWizard));

using typeof(CreateUserWizard).Assembly (with ".Assembly") instead, will
make it comilable.

The solution you have provided works great. Thanks a lot!

Best regards,
Dieter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,097
Latest member
RayE496148

Latest Threads

Top