Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / April 2006

Tip: Looking for answers? Try searching our database.

How to "Imports Resources" into compiled custom controls?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Samuel - 25 Apr 2006 10:41 GMT
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.
Steven Cheng[MSFT] - 26 Apr 2006 02:58 GMT
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.

Signature

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.