How can I use resources in aspx files?

I use WebResources.resx to translate all the lines to the web interface. It works like:

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

But if I try to use onClientClick-Attribute, the line 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 %>');" />
+3
source share
2 answers

I'm not sure what the problem is when asp.net renders your lines, but one way to fix it would be to set the property OnClientClickin the code:

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

You can try adding the onclick handler to the code

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

Source: https://habr.com/ru/post/1734319/


All Articles