views:

54

answers:

2

I've got an ASP.net file, and I'm trying to include dynamic code which was easy in classic ASP.

Here is what I have tried so far:

<%@ Register TagPrefix="TagPre" TagName="header" Src="alg/classes.aspx"%> 

and

<!--#include file="alg/classes.aspx"-->

But neither of these seem to work. The content of classes.aspx is:

<script runat="server">   
' Square class
Public Class square

    Public sqRows As Integer        'Numbers of rows this square has
    Public sqCols As Integer        'Number of columns this square has
    Public sqArray(,) As Integer    'The square array

    ' Initialise square array to match size of canvas
    Public Sub initSqArray(ByVal canvCols, ByVal canvRows)
        ReDim sqArray(canvCols, canvRows)
        sqRows = canvRows
        sqCols = canvCols
    End Sub

End Class

Thanks for any help!

+1  A: 

What is the concrete problem or error you got? When you are using .aspx, did you already try to put the VB-Code in the Code-Behind-Sheet and pull it from there?

One of the errors I got is 'square is not defined' in the main file, as it doesn't seem to be including the class properly or something. I'm unsure what a code behind sheet is, but can I use multiple of these?
Tom Gullen
"http://en.wikipedia.org/wiki/ASP.NET" Theres also something about Code-Behind. Normally, every simple page got an extra Code-Behind-Sheet. With which IDE do you write?
I'm using Visual Studio but I'm very new to developing ASP.net, I've done a ton of classic ASP though and I just used to have a whole load of include statements.
Tom Gullen
I guess you should try the Code-Behind, so you have the Design in the aspx-pages and the coding and dynamic behaviour in the Code-Behind-pages. So, I would advice you to read a Code-Behind-Tutorial, because this is on of the most important and best changes of .NET, so it should not only solve your problem but improve your skills.
+1  A: 

You should not need to use include or register to access a class. You just need to save your class to a class file (.vb) and put the class in your app_code directory (if you are using a website project) or put it anywhere in a web application project (preferrably a folder for classes) but include it in your project namespace. This should make your class visible anywhere in the website or web application.

Chris Mullins