Search code examples
asp.netlocalizationwebformsresource-files

How can i assign resource file value to and asp.net hidden field


I am in a situation where i need to read a value from from asp.net hidden fields

<asp:HiddenField ID="hdSearchInnerText"  runat="server" 
    Value="What are you looking for?" /> 

This is for a multilingual website and and i need to read value for the above hidden field from the resource .resx file real issue is that asp.net hidden fields doesn't take meta:resourcekey="hdSearchInnerText" as a property. How can i get around this i tried and could not find a fix.

Any idea or help is appreciated.


Solution

  • In your code behind, you could write something like:

    this.hdSearchInnerText.Value = this.GetLocalResourceObject("hdSearchInnerText").ToString();
    

    Alternatively, you can explicitly use resources from the App_GlobalResources repository:

    <asp:HiddenField ID="hdSearchInnerText"  runat="server" 
    Value="<%$ Resources:ResourceFile, hdSearchInnerText %>" /> 
    

    where ResourceFile is the name of the global Resource file and hdSearchInnerText is the name of the Resource Text which has the value "What are you looking for?".