views:

257

answers:

3

when trying to translate the confirmation message to Norwegian i get the following error:

Cannot have more than one binding on property 'OnClientClick' on 'System.Web.UI.WebControls.LinkButton'. Ensure that this property is not bound through an implicit expression, for example, using meta:resourcekey.

i use Explicit localization in the following manner:

<asp:LinkButton ID="lnkMarkInvoiced" runat="server" OnClick="lnkMarkInvoiced_OnClick"
            OnClientClick="<%# Resources: lnkMarkInvoicedResource.OnClientClick%>"
            Visible="False" CssClass="stdtext" meta:resourcekey="lnkMarkInvoicedResource" ></asp:LinkButton>

here's the local resource file entry:

  <data name="lnkMarkInvoicedResource.OnClientClick" xml:space="preserve">
<value>return confirm('Er du sikker?');</value>

if i remove the meta attribute i get the English text(default). how do i get the Norwegian text appearing without resorting to using the code behind?

Update:

removing the meta attribute prevents the exception from occurring but the original problem still exists. I can't get the Norwegian text to show.

only the default English text shows.

Another Update:

I know this question is getting old but i still can't get the Norwegian text to display. If anyone has some tips please post a response.

+1  A: 

Are you using the .NET resource manager and satellite assemblies to store your localized resources? It looks like you have hard-coded the alternative language in your markup, rather than storing it in a language-specific resources assembly...

.NET has some extremely rich localization and globalization capabilities. If you use them properly, localization should be a pretty automatic thing (assuming your client is providing their language code as part of the HTTP headers). Even if your client has not configured their browser with the appropriate language, it is still easy enough to manually change the UI culture via a user request (clicking a flag icon, configuring a setting, etc.)

This article might be helpful: ASP.NET Web Page Resources Overview

jrista
>"Are you using the .NET resource manager and satellite assemblies to store your localized resources?"Yes the Satellite assemblies are created using the resource files located in the appropriate App_LocalResources folder.the localization info is assigned to the current thread when the user selects a flag in one of the previous steps.
X-Dev
The following page might help solve your problem: http://www.asp.net/ajax/documentation/live/tutorials/LocalizeResourcesInScript.aspx
jrista
not really applicable in this case.
X-Dev
A: 

That meta tag is using implicit localization when you're using explicit localization in the OnClientClick. You will need to choose one method or the other. If you are to use explicit localization, you'll need to do the necessary work to set the proper culture info in your application in the code-behind.

Steve Danner
according to http://daffodilsw.com/blog/2009/11/Multiple-language-support-in-an-Asp.Net-application-using-local-resource-files.htmlthe meta tag is required.since it wasn't working i saw trying to cover all bases.i checked on msdn and it doesn't appear to be required for explicit localization.
X-Dev
It is certainly required for explicit localization. But you are mixing it with implicit localization with the line OnClientClick="<%# Resources: lnkMarkInvoicedResource.OnClientClick%>". If you remove that and ensure that <data name="lnkMarkInvoicedResource.OnClientClick" xml:space="preserve"><value>return confirm('Er du sikker?');</value>is also in your default resx file, it should be fine.
Steve Danner
implicit wont work as it's not a 'Bindable' property.
X-Dev
A: 

Looks like you're making the problem harder by inlining the onclick. Why not split it out to a separate line?

<script>
  function markInvoiced()
  {
    return confirm('<%= Resources.SomehowGet.lnkMarkInvoicedResource.OnClientClick%>');
  }
</script>
<asp:LinkButton ID="lnkMarkInvoiced" runat="server" OnClick="lnkMarkInvoiced_OnClick"
        OnClientClick="return markInvoiced();"
        Visible="False" CssClass="stdtext" meta:resourcekey="lnkMarkInvoicedResource" ></asp:LinkButton>

And while we're looking at your code, you realize that you're essentially building an <a> tag, right? As such, why not just build an <a> and save yourself some grief?

And finally, next project why not ditch the built-in ASP.NET localization nighmare in favor of something sane like FairlyLocal, in which case you'd write this:

<a href="#" onclick="return confirm(<%=_"really?"%>) onserverclick="lnkMarkInvoiced_OnClick" runat="server">
  <%=_("Mark Invoice")%>
</a> 
Jason Kester
It sounds like you've gone through a few of the headaches I'm going through.Changing the LinkButon to a server site anchor won't save me any grief.Separating the javascript MarkInvoice function is a good workaround for the problem.I've had a look at FairlyLocal and I'm quite impressed.the only disadvantage is that id dosen't generate UTF8 files.I love that it's open source.
X-Dev
Thanks for that. I forgot to disclaim that I wrote the FairlyLocal code. The UTF8 thing is simple enough to fix, but then it might not get attention anytime soon since it really only ever happens once per project, and then only if you don't simply create a .po file by hand and drop it into the right directory. Once you load/save the file in an editor to fix the encoding, it'll stay that way for future merges.
Jason Kester