开发者

Explicit localization problem

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 开发者_C百科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.


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> 


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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜