Last post Nov 26, 2007 06:29 AM by enriverd
Nov 15, 2007 03:57 AM|enriverd|LINK
I've been facing some problems trying to localize dynamically generated controls with implicit localization. I have a page that gets its controls from databse, so all the controls are created with the page.ParseControl method. The real situation is quite
comlpex, but I've been albe to isolate the problem to the following lines of code:
string str = "<asp:Label ID='LabelParsed3' runat='server' meta:resourcekey='LabelParsed3'/>";
Control c3 = Page.ParseControl(str);
When the page runs I get the following error:
NullReferenceException: Object reference not set to an instance of an object.
The error seems to be related to the use of the meta:resourcekey with the method Page.ParseControl. If I remove the meta:resourcekey attribute everything works fine, and If I replace that attribute by a resource expression pointing to the local resource file,
like the following code shows:
string str="<asp:Label ID='LabelParsed3' Text='<%$Resources:LabelParsed3.Text%>' runat='server'/>";
I still get the same error. However, if the resource expression points to a global resource file:
string str="<asp:Label ID='LabelParsed3' Text='<%$Resources:GlobalRes,LabelParsed3.Text%>' runat='server'/>";
Then, everything works fine again. I'm starting to think that something in the ResourceExpressionBuilder is not correctly initialized when trying to access a local resource for a control created by ParseControl.
Has anyone faced the same problem? Any idea on how to solve this would be greatly appreciated.
Thanks for your help!
Nov 18, 2007 07:42 AM|enriverd|LINK
After investigating a little, well not that little but many hours, I discovered that the meta:resourcekey attribute is translated into C# lozalization expressions at compile time. Those expression are similar as a property value assignment retrieving the
value assigned with the GetLocalResourceObject method or equivalent. Anybody knows if those expressions are also created by page.ParseControl, or is this a feature that is not compatible with that method?
Nov 26, 2007 06:29 AM|enriverd|LINK
I do believe it is a bug from the famework and I've submitted it to Microsoft. I someone is also interested on its resolution, please, vote its importance: