Databinding Server Controls – Learned Something New
Date Published: 16 August 2003
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
Steve is an experienced software architect and trainer, focusing on code quality and Domain-Driven Design with .NET.