I have some problem with the Localization in ASP.net. I have generated t开发者_如何学运维he resources and binding the text property by an variable. In the source file.
<asp:Label ID="Label1" runat="server" Text='<%# Eval("name") %>' meta:resourcekey="Label1Resource1"></asp:Label>
code behind
protected string name;
protected void Page_Load(object sender, EventArgs e)
{
name = "Hello World";
}
The above things are simple but when I run the project. I got
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Cannot have more than one binding on property 'Text' on 'System.Web.UI.WebControls.Label'. Ensure that this property is not bound through an implicit expression, for example, using meta:resourcekey.
Source Error:
The above is just an example what I am facing in my project.
Please Help me how can I make localization and binding both at the same time.
What Solution I found is Making the data in between the tags.
like
<asp:Label ID="Label1" runat="server" meta:resourcekey="Label1Resource1"><%# Eval("name") %></asp:Label>
But this also leads to another problem.
What if I want to access the value of that label inside code behind.
You can use only one binding at a time on Page events. If you want to use both binding then it must besides in different events.
Avoid placing the Text attribute in the markup, as it's already bound to the localized text in the resource file, and just call Label1.Text = "hello world".
精彩评论