Keeping scripts out of HTML pages

gdboling

Member
Joined
Jul 11, 2003
Messages
12
Location
Wichita, KS
I am just getting started with ASP.NET and had a question.

Consider the following simple code

Code:
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
lbl1.Text="Hello " & txt1.Text & "!"
End Sub
</script>

<html>
<body><form runat="server">
Your name: <asp:TextBox id="txt1" runat="server" />
<asp:Button OnClick="submit" Text="Submit" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form></body>
</html>

Can you put the <script> block in a completely seperate file and use it on that page?

Thanks.

Gregg
 
Yes, for example the following will link to a JS file in a directory named javascript.
Code:
place the following in the <head> tag.
<script src=javascript/main.js></script>
 
Serversode code can written in a extra file.

For C#: YourPage.aspx.cs
For VB: YourPage.aspx.vb

First line of your HTML file:
Code:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<

Should work...
 
Back
Top