Rocco Hundertmark
Rocco Hundertmark

Reputation: 563

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-Attribute, 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 %>');" />

Upvotes: 3

Views: 5514

Answers (2)

Scott Schulthess
Scott Schulthess

Reputation: 2923

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

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

Upvotes: 0

Steve Danner
Steve Danner

Reputation: 22148

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);

Upvotes: 1

Related Questions