How to Embed JavaScript in Asp.net

ASP.NET is a Web development application framework developed and deployed by Microsoft. An upgrade to its predecessor, ASP, ASP.NET allows for the development of dynamic Web pages and websites. JavaScript is a client-side scripting language used in Web pages to add interactivity, animations and effects. When you're developing ASP Web pages, it is not uncommon to see the two technologies working side by side. Embedding JavaScript code into an ASP.NET page takes an understanding of the two platforms and of Web programming, but once you've gained that understanding, the process takes just a few minutes.

Instructions

    • 1

      Open Notepad.

    • 2

      Type or copy and paste the following code:

      <%@ Page Language="VB" %>

      'javascript code

      <script runat="server">

      Sub Page_Load(sender As Object, e As EventArgs)

      Button1.Attributes.Add("onclick", _

      "javascript:alert('ALERT ALERT!!!')")

      End Sub

      </script>

      'javascript code

      <html>

      <head>

      </head>

      <body>

      <form runat="server">

      <asp:Button id="Button1" runat="server" Font-Bold="True"

      Font-Names="Verdana" Font-Size="Larger"

      Text="Click Me!"></asp:Button>

      </form>

      </body>

      </html>

    • 3

      Click "File" and then "Save as." Select "All Files" as the "Save as type."

    • 4

      Save your file as an ASP.NET file by typing ".ASPX" at the end of the file name, for example, EmbedJavaScript.ASPX. In order for your ASPX file to work and execute, you must save it as an ASP.NET file.

Related Searches:

References

Resources

Comments

Related Ads

Featured