turzifer
turzifer

Reputation: 431

c# code in control attribute in aspx file

I'd like to change the text attribute of a button according to the session landuage. So I write:

<asp:Button id="btOptIn" runat="server" 
    Text="<% = UI.Instance.TxtSubmit %>"
    onclick="btOptIn_Click" />

This does not work. I tried several other versions (like Text='<%# Eval(UI.Instance.TxtSubmit) %>') but could not succeed.

The same code (<% = UI.Instance.TxtSubmit %>) works outside the quotes of the attribute. What is the syntax to make it work within an attribute of a control?

Thank you for your time.

Upvotes: 1

Views: 617

Answers (1)

Madhur Ahuja
Madhur Ahuja

Reputation: 22681

<asp:textbox id="tbName" runat="server" Text='<%# Eval("test") %>' />

<%= %> is a shortened response.Write() and is never valid as an attribute, for any server tag.

<%# %> can be used, only if the conatainer is databound (the page in your case).

<%$ > can be used to access data in resources files.

In the Page_Load of you will have to make a call to Page.DataBind() for this to work.

Upvotes: 3

Related Questions