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

天大地大妈咪最大 提交于 2019-12-30 06:03:06

问题


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.


回答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.




回答2:


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

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



回答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().




回答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")) %>'




回答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




回答6:


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




回答7:


Use this method to append 2 strings in ASPX.

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


来源:https://stackoverflow.com/questions/1762979/how-do-i-concatenate-2-resource-strings-together-in-an-aspx-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!