locked
LocalResources in Code Behind RRS feed

  • Question

  • User-1680963127 posted

    Hi!

    Is there any way to reference a LocalResource file .resx in CodeBehind?

    I have a multilingual web project with several LocalResources and i would like to add some custom values to them, which I like to use in CodeBehind, for example:

    DropDownList.Items.Add(<string from LocalResource file depending on user language>)

    Thanks in advance for your responses.

    Monday, March 27, 2006 4:56 AM

Answers

  • User1183903743 posted

    All these methods get the current culture from the thread. Best way to access that in your case would be right form the static properties: 

    this.Page.Culture
    this.Page.UICulture

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 28, 2006 11:32 AM

All replies

  • User1183903743 posted

    DropDownList.Items.Add(HttpContext.GetLocalResourceObject("/App_LocalResources/theResource.resx", "theNodeName"));

    or directly:

    DropDownList.Items.Add(this.GetLocalResourceObject("theNodeName"));

    Monday, March 27, 2006 12:54 PM
  • User-1680963127 posted

    Yeah, thank you, works great!

    The direct method gets the language info from CultureInfo, right?

    So I can influence the automatically chosen .resx-file by changing the thread`s CultureInfo, can I?

    Tuesday, March 28, 2006 2:34 AM
  • User345984983 posted

    Hello if you want to use HttpContext.GetLocalResourceObject
    don't forget to use "~" before the path of the resource.
    I've got the same problem in the codebehind.
    But the easiest way to get the local resource is in the code behind from the Page and call

    Me.GetLocalResourceObject("resourceId")

    Tuesday, March 28, 2006 5:06 AM
  • User1183903743 posted

    All these methods get the current culture from the thread. Best way to access that in your case would be right form the static properties: 

    this.Page.Culture
    this.Page.UICulture

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 28, 2006 11:32 AM