views:

865

answers:

2

Hello:

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

A: 

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.......

DOK
Thanks - I'll check out the article. I was actually going to post another question about Javascript functions and code-behind. I cannot figure out how to create a file to add javascript code-behind in Visual Studio.
A: 

you need to add onmouseover attribute in code behind

refer link below for example

highlight gridview row on mouseover