How do I concatenate 2 resource strings together in an aspx page

I have a localised ASP.net application (.net 2.0). I wish to concatenate 2 strings retrieved from the resource file together into one element, something like this.

Text="<%$ Resources:Resource, lw_name %>" + <%$ Resources:Resource, lw_required %>"

I have tried using Eval without success. Is what I am trying to do the “correct” approach or can I store strings with placeholders in the resource file and interpolate them “on the fly”.

I am trying to do this in the aspx file rather than in code-behind.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

ASP.NET tag attribute values that use <%$ Something: Something Else %> are of a special syntax called ASP.NET Expressions. Using them as attribute values are pretty much all-or-nothing; there’s no way to add any code into the ASPX file to manipulate what those expressions evaluate to. You’ll have to do this in the code-behind.

Method 2

I search for the solution so long
This code works for me:

ToolTip='<%# Resources.Global.Btn_Edit + "/" + Resources.Global.Btn_contact %>'

Method 3

< asp:HyperLink ToolTip='<%# “Some Text :” + Eval(“id”).ToString() %>’ ……/>

Do you mean something like this…. ToolTip=’…’ -> Convert your return values to STRING… ( xxxx.ToString() )

Like this it displays: Some Text: 1234 –> on Tooltip

so you should do something like this in your case:
Text=”<%$ (Resources:Resource, lw_name).ToString() %>” + <%$ (Resources:Resource, lw_required).ToString() %>”

I don’t know if it’s going to work but try to conver to ToString().

Method 4

I know you said you tried eval but what about something like this:

Text='<%# string.Format(“{0}{1}”,Eval(“lw_name”),Eval(“lw_required”)) %>’

Method 5

I was having the same issue, and I solved it by using this option instead:

Text="<%= HttpContext.GetGlobalResourceObject("Resource", "lw_name") %> <%= HttpContext.GetGlobalResourceObject("Resource", "lw_required") %>"

For local Resources, use the GetLocalResourceObject method instead of GetGlobalResourceObject

Method 6

Try
"@(Resources.ResourceString + Resources.ResourceString)"

Method 7

Use this method to append 2 strings in ASPX.

Text='<%# String.Format("{0} {1}", 
      Resources.file01.string1,Resources.file01.string2)%>'

Method 8

This Might Be of Help

<asp:Label ID="Mylabel" runat="server">  
  
<%= "before Message String- "+ Resources.MyResources.Message +" -After Message String " %> 

</asp:Label>

Note the concatenation is not on the Text attribute but between the label element
Full post can be found here


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x