I’ve created a table in my ASP.NET (C#,VS2010) web app whose rows and cells should be created dynamically (read from DB), I have an image in each row which is being created dynamically (in codebehind file), how can I change its image (display a hover) with mouse over? it is easy using a small JavaScript function for statically created controls, but how can it be done for dynamically created controls? can I use inline JS functions? how should I implement it?
thanks
Give the images you create dynamically a class, using their
CssClassproperty:This will render each image like this:
Then in jQuery, you can find all the images with this class to bind the behavior:
The
data-alternative-imageattribute is a nice way to store some information inside the image tag from code behind, that you can then later read in your JavaScript event handler. You can make your own data-attributes any way you like.Some more info about the data-attribute: http://ejohn.org/blog/html-5-data-attributes/