1

I have some problem with the Localization in ASP.net. I have generated the 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.

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

different Evenets means. Can you eloberate.
At a time we can not bind particular control with values. so you can bind with different events like Page Load, Button Click ,Page PreRender etc. events
0

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".

1 Comment

What If the Label is placed inside the GridView Itemtemplate. I dont want that heavy FindControl method in the RowDataBound.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.