I have a repeater containing several several panels.
I have noticed that there is no onmouseover attribute of the <asp:Panel>.
I have read that I can add the attribute to the panel by calling in the page_load:
PanelID.Attributes.Add("onmouseover", "Script to Run");
The problem is that I am in a repeater, and the PanelID is generated by asp.net like ContentPlaceHolder_ctl01_myID_0 so not only it is hard to figure out, but VS2010 does not recognise it as a proper object and throws an error on it, plus I have to attach it on every item, so I need to use a for or foreach, but I don’t know what to iterate on.
Is there a way like
foreach(childcontrol in Repeater.ChildControlsISpecificallyNeedPossiblyIdentifiedBySomeID)
{
childcontrol.Attributes.Add("onmouseover", "Script to Run");
}
to do this in C# in the Page_Load eventhandler?
I want to run a client side onload, onmouseclick and onmouseout on the panels too, so I want to attach those attributes too.
Thinking outside the box, instead of specifying the
onmouseover-attribute inline using ASP.NET, you can attach the javascript event listeners in javascript.Give the panel a CSS class:
Using jQuery, the syntax to bind the event handlers would be as follows:
If you’re not using jQuery, you’ll need a bit more code, but I’m sure you get the idea.