开发者

How can I use resources in ASPX-files?

I use a WebResources.resx to translate all strings in the Web UI. It works like:

<asp:Button ID="Button1" runat="server" 
Text="<%$ Resources:WebResources, Button1Caption %>" />

But if I try to use the onClientClick-Attribu开发者_开发技巧te, the string will not be resolved. What's wrong? Or how can I do it right?

<asp:Button ID="Button1" runat="server" 
Text="<%$ Resources:WebResources, Button1Caption %>" onClientClick="return confirm('<%$ Resources:WebResources, ConfirmThisClick %>');" />


I'm not sure what the issue is when asp.net is rendering your strings, but one way to fix it would be to set the OnClientClick property in the code behind:

Button1.OnClientClick = string.format("return confirm('{0}')", WebResources.ConfirmThisClick);


You can try adding the onclick handler in the code-behind

Button1.Attributes.Add("OnClick","DoStuff(" + WebResources.ConfirmThisClick =");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜