Tominator
Tominator

Reputation: 1224

Asp.net binding a property in ascx not updating on postback

In my aspx file i have this:

addServiceOption(list, {
    ID: null,
    Name: '<%# SelectItemText ?? "[Select a service..]" %>'
});

and in my code-behind i have of course this property:

public string SelectItemText { get; set; }

When i change the language on my page, it causes a postback and the new language cookie is set, but that code is irrelevant here, it works.

With breakpoints i've seen that the setter of SelectItemText gets the string in the new language. However, i see that the getter is not called on postback.

I'm pretty sure the <%# %> syntax (which is impossible to search more info about if you don't know the name of the construct) means: only bind this data once, then never again.

The simple solution would be to make a which i databind the text value to on each postback, but that's a bit too hardcoded and specific for me. Is there a more general solution?

Cheers!

Upvotes: 0

Views: 504

Answers (1)

Tim B James
Tim B James

Reputation: 20374

Change <%# to <%=

Does that work for you?

Upvotes: 1

Related Questions