Search code examples
javascriptasp.nethtmlvisual-studio-2010visual-web-developer-2010

How to combine javascript into html / ASP.Net in visual web developer?


I want to create scripts, and then call them from the html code or the ASP.Net codebehind. How do I do that?

This is probably very simple, but Googling hasn't helped.

For example: I want an ImageButton to have an onmouseover="this.src='...'". But I want the script to be separate instead of inline.


Solution

  • Especial for this part of your code

    onmouseover="this.src='...'"
    

    you make a function as

    <script>
      function cOnMouseOver(me)
      {
         me.src='...';
      }
    </script>
    

    and you call it as : onmouseover="cOnMouseOver(this);"

    or set it on code behind using the Attributes of this control