How to "Imports Resources" into compiled custom controls?

S

Samuel

Hi,

I am building a custom control for a Web Application in ASP.NET 2.0 that
makes use of the name space "Resources" for localization
(app_globalresources) by adding this to the top of the customcontrol.vb file
in the app_code directory:

Imports Resources

However, when I move the file to a project of its own, the reference to
Resources cannot work anymore for understandable reasons since resources is
not part of the project. How do I make use of the global resource of the web
application for the custom control?

Do I have to create a resource for the custom control? I want to keep
localization in one place though.

Do I have to leave the custom control in App_Code if I want localization to
be in one place?

Please let me know if it is possible.
 
S

Steven Cheng[MSFT]

Thank you for posting .

From your description, you're developing some custom ASP.NET web control,
and the webcontrol will use some resources in the ASP.NET application's
Global or Local Resource collection to perform some localization work.
Howerver, you found it works well when put in the ASP.NET app's App_Code
dir, when moved to a separate class library project, it stoped working,
correct?

Based on my understanding, as for the Global/Local Resources in ASP.NET
application, they can be retrieved through declarative syntax or
programmatic syntax. I think you are using the programmatic approach (the
GetGlobalResourceObject and GetLocalResourceObject method). If this is
the case, in your custom classlibrary project, if your custom control still
want to utilize these methods, you need to reference System.Web.dll
assembly, and then, use the HttpContext's static methods to reference the
two methods, e.g.

protected override void RenderContents(HtmlTextWriter output)
{
string value =HttpContext.GetGlobalResourceObject("strings",
"key1").ToString();

output.Write("<br/>Key1: " + value);
output.Write(Text);
}

The following msdn document has also mentioned the HttpContext class for
the two methods:

http://msdn2.microsoft.com/en-us/library/ms227982(VS.80).aspx

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


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

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

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


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



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

No members online now.

Forum statistics

Threads
473,951
Messages
2,570,113
Members
46,699
Latest member
Abigail89S

Latest Threads

Top