locked
Resource file RRS feed

  • Question

  • User1369066894 posted

     Hi, I have a question regarding resource files. I am using Visual Studio 2003 and there is a resx file for each aspx file in my projects.

    The first question is How can I retrieve resources from these files in order to use them in my aspx page?

    The second question is, where do these files go after compilation?

    I will wait for you replies.

    Thank you in advance. 

     

    Tuesday, October 2, 2007 3:18 AM

Answers

  • User1642585364 posted

    For local resources (under App_LocalResources; typically these are where you have one per .as*x), you can access them a couple ways:

    1) Implicit localization - this requires adding a meta:resourcekey attribute to the control tag where the value of the attribute is the entry in the .resx file, e.g. <asp:Button ID="Button1" runat="server" meta:resourcekey="Button1Resource1" /> will load the Button1Resource1.Text and Button1Resource1.Tooltip values from the .resx file.

    2) Explicit localization - this just sets the property directly from the resource, rather than loading all associated ones, e.g. <asp:Button ID="Button2" runat="server" Text='<%$ Resources: ButtonText %>' /> will load the associated value from the .resx file.

     If you use global resources (under App_GlobalResources; these are typically shared across different .as*x files), you use explicit localization, but you need to add the class name (e.g. <asp:Button ID="Button2" runat="server" Text='<%$ Resources: GlobalResourceClass, ButtonText %>' will load the associated resource.

     Resources are compiled into satellite assemblies dynamically, so you don't have to do anything about them.  Rather, you can't really, since you don't even know the name of the assembly.

     [edit:] I should mention: this is based on ASP.NET 2.0.  If you're using 1.1, it's a different monster entirely.  Also, MSDN might be useful either way.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 2, 2007 11:52 AM
  • User-1506829456 posted

    Hi,

    The ASP.NET 1.1 does not support implicit or explicit localization like jamlew mentioned. In ASP.NET 1.1, you have to create a ResourceManager object and get the string from it with code. Here is a quick sample code.

    ResourceManager rm = new ResourceManager("myApp.Resource1", a);
    String s = rm.GetString("foo");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 5, 2007 2:43 AM

All replies

  • User1642585364 posted

    For local resources (under App_LocalResources; typically these are where you have one per .as*x), you can access them a couple ways:

    1) Implicit localization - this requires adding a meta:resourcekey attribute to the control tag where the value of the attribute is the entry in the .resx file, e.g. <asp:Button ID="Button1" runat="server" meta:resourcekey="Button1Resource1" /> will load the Button1Resource1.Text and Button1Resource1.Tooltip values from the .resx file.

    2) Explicit localization - this just sets the property directly from the resource, rather than loading all associated ones, e.g. <asp:Button ID="Button2" runat="server" Text='<%$ Resources: ButtonText %>' /> will load the associated value from the .resx file.

     If you use global resources (under App_GlobalResources; these are typically shared across different .as*x files), you use explicit localization, but you need to add the class name (e.g. <asp:Button ID="Button2" runat="server" Text='<%$ Resources: GlobalResourceClass, ButtonText %>' will load the associated resource.

     Resources are compiled into satellite assemblies dynamically, so you don't have to do anything about them.  Rather, you can't really, since you don't even know the name of the assembly.

     [edit:] I should mention: this is based on ASP.NET 2.0.  If you're using 1.1, it's a different monster entirely.  Also, MSDN might be useful either way.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 2, 2007 11:52 AM
  • User-1506829456 posted

    Hi,

    The ASP.NET 1.1 does not support implicit or explicit localization like jamlew mentioned. In ASP.NET 1.1, you have to create a ResourceManager object and get the string from it with code. Here is a quick sample code.

    ResourceManager rm = new ResourceManager("myApp.Resource1", a);
    String s = rm.GetString("foo");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 5, 2007 2:43 AM