开发者

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开发者_如何学Go.

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.


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.


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

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


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


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

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


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


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


Use this method to append 2 strings in ASPX.

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜