views:

818

answers:

1

I have a label on a page which gets localized text through the meta:resourcekey attribute. The issue I have is that I want it to display different text depending on which view of a multiview they're on.

I tried adding the attribute though label.Attributes.Add("meta:resourcekey", "label"), but that doesn't seem to load any text. I tried it on PreRender, and same deal. The attribute appears when I look at the source, but no text is displayed.

Is this possible to do? The other option is to have 2 labels and change the visibility on page load, but that seems like the less elegant solution.

Thanks.

+3  A: 

The approach of trying to assign a meta:resourcekey attribute will not work simply because they are treated specially by the page parser, and replaced before the page lifecycle code even really begins.

But meta:resourcekey is basically a declarative replacement for the code equivalent of accessing local resource files. In other words:

<asp:Label ID="MyLabel" meta:resource-key="MyResourceKey" />

is equivalent to:

<asp:Label ID="MyLabel" Text="<%$ Resources: myResXFile, MyResourceKey %>" />

is equivalent to the code:

MyLabel.Text = Resources.MyResXFile.MyResourceKey;

It looks like you're already dealing with your label in the code if you're trying to assign attributes to it. Why not set it's value in the code?

womp