Databinding Server Controls – Learned Something New

I was running into an issue databinding an ImageButton’s ImageUrl property to a string comprised partly of literal text and partly of a string I was pulling from my ConfigurationSettings.AppSettings collection. I was using the standard <%# … %> syntax for the databinding, but the result kept showing my databinding syntax in the button’s URL, rather than the actual value. It seems that while you can do the databinding to the control property, it’s all or nothing. So if you want the string to be:

<asp:ImageButton … ImageUrl="/folder/<%# MyConfigVariable %>/Add.gif" … />

Then you need to code it like this (VB):

<asp:ImageButton … ImageUrl='<%#"/folder/" & MyConfigVariable &"/Add.gif" %>' … />

Thanks a bunch to Andy Smith for helping me see the light.

Listening to: Command and Conquer – Hell March

If you liked this post, consider subscribing to email updates about my new posts, or sharing it on Hacker News.

Keyboard shortcuts

?
Show this help
Esc
Close this help or an open menu
n
Next (newer) post: Object Must Implement IConvertible with MS Data Access Application Block
p
Previous (older) post: unexpected error creating debug information
Tab
Move between links and buttons (Shift+Tab to go back)