简体   繁体   中英

Javascript and ASP.NET with Visual Studio OnMouseOver Control Validation Error

I just started working with Javascript and I ran into an error with Visual Studio stating, "Validation (ASP.Net): Attribute 'onMouseOver' is not a valid attribute of element 'Button'". Basically, I entered onMouseOver="this.style.color='Red'" within the HTML code of a button control. When I run my web project, the mouse over command works just fine; however, the error message is posted.

What should I do to resolve this error or is this error message not critical, since the mouse over command works well?

Thank you,

DFM

Visual Studio does not like javascript within <asp:..> server control tags. Their preferred approach is to wire up the javascript in code-behind, for example by using ClientScript.RegisterStartupScript . Here's an MSDN article explaining their official approach.

I believe that the purpose for doing it this way may be so that ASP.Net can render browser-specific code.

But hey, if your code works.......

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM