Adding Events to Web User Controls
-
I have created a user control with an image and a label in it. I want to add an event when the user control is clicked to change the back color of the label (within the user control). How can I achieve this? Thanks! :)
-
I have created a user control with an image and a label in it. I want to add an event when the user control is clicked to change the back color of the label (within the user control). How can I achieve this? Thanks! :)
You can do this with javascript. Add an
onclick
attribute to the<span>
that encapsulates your control and tie it to a javascript function. In the function, then set the backcolor of the label. Doing it this way, you eliminate the postback to your page. Does that work for you? ~Javier Lozano -
You can do this with javascript. Add an
onclick
attribute to the<span>
that encapsulates your control and tie it to a javascript function. In the function, then set the backcolor of the label. Doing it this way, you eliminate the postback to your page. Does that work for you? ~Javier LozanoIt will work for me i suppose. But i've seen a few articles that can do in all within .Net. It just that I don't get it =( I was hoping that someone would be kind enough to guide me. Oh well, back to reading them articles i guess! Thanks!
-
It will work for me i suppose. But i've seen a few articles that can do in all within .Net. It just that I don't get it =( I was hoping that someone would be kind enough to guide me. Oh well, back to reading them articles i guess! Thanks!
If the event is for an action internal to the user control , it is better to use javascript you can atleast avoid a post back. But if the event raised is to be notified to the page containing the user control only then is it worthwhile to consider adding a event to the user control and using it on the page and causing post back Think about it Thanks Srinivas