Mark, I’ve reviewed the original thread and have a few comments for you.
First, a direct converson between the two is not possible due to several reasons. These reasons would be a difference in the underlying technology and the fact that vbscript (used in the InterDev days) is no longer used.
Second, rather than convert your script, please allow me to show you how to do this conversion. Then you can learn more along the way, as you convert your scripts yourself. It’s always best to learn by doing.
I’ll assume you have something akin to the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Page</title>
<%
sub GetHeaderText()
GetHeaderText = "Howdy all"
end sub
%>
</head>
<body>
<h1><%Response.Write(GetHeaderText()) %></h1>
</body>
</html>
And that it is giving you the “cannot exist within a method” error, correct? The reason for this is because asp.net is compiled, managed code. It is just as much a full project as when you would write a custom DLL in VB to provide DAL services for your asp.classic application. In this case, we’re trying to add the method GetHeaderText to a global namespace, which isn’t allowed. Therefore, we have a different way of handling this.
To make the conversion, we add the following to a asp.net web application project…
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Conversion.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1 id="MyHeader" runat="server" onload="MyHeader_OnLoad"></h1>
</div>
</form>
</body>
</html>
using System;
using System.Web.UI;
namespace Conversion
{
public partial class Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
Title = "My Page";
}
protected void MyHeader_OnLoad(object sender, EventArgs e)
{
MyHeader.InnerHtml = "Howdy all";
}
}
}
Now the file runs correctly. All we’ve done is wrapped the base functionality of the entire page in a class, which exposes methods the client html can hook into. You do not, in fact, need to resort to using all the nifty built-in <asp:whatever> controls to use aspx. These controls have a lot more options and settings, and are far more customizable than stock html elements, but you can do the same things with normal html. All that’s required is that you give the element id and runat attributes, and map your events to handlers. One of the biggest advantages of this is that we can now use inheritance to create a base page handling class, subclassing it for specific page usage. Also note the first line in the new html. There are directives there that tell the compiler which language you’ll be using, which file has the code (no need for SSI anymore, yay), and what namespace.class to use.
I hope this simple example helps clarify what needs to be done to convert your scripts.
In addition, you may still use javacript, AJAX, and anything else you want in the HTML portions of your page.
I realise you are hesitant about .net, and I understand why. It’s a bit of a shift in thought. But you can not easily take a Chevy (your asp.classic app) and toss a Ford engine (.net) into it and expect it to work without reworking a few things. Might I suggest that you simply take a leap of faith? Download and install the free MS Web Express IDE, try authoring a few pages to get the feel for it, and then try the conversion. At worst, you’ve lost a day or two of time exploring things, but you’ll have a much better grasp on how it all works, in order to place future queries.
Happy coding. =)