Using Classes and Modules

Results 1 to 3 of 3

Thread: Using Classes and Modules

  1. #1
    Join Date
    Dec 1969

    Default Using Classes and Modules

    This may seem like a easy question, but I can&#039;t get to use Classes/modules created in an external (.vb file) with an aspx page. Both the files are in the same folder.<BR>I get a compiler error message that the class is not defined:-<BR>Here&#039;s my code for the .vb file<BR><BR>namespace NewNameSpace<BR> Public Class Class1<BR> Public Function GETMyString() as String<BR> GetMyString="Test Page" <BR> end function<BR> End Class<BR>end Namespace<BR><BR>The code in the aspx page is:<BR>&#060;HTML&#062;<BR>&#060;% @Import namespace="NewNameSpace" %&#062;<BR>&#060;Script language="VB" runat="server" &#062;<BR> <BR>Sub Page_Load(sender as Object, e as EventArgs)<BR>If Not Page.IsPostBack then<BR><BR> dim newClass1 as New Class1<BR> label1.text = newClass1.GETMyString<BR> End if <BR><BR>End Sub<BR><BR>&#060;/SCRIPT&#062;<BR><BR>Any ideas why it says that Class1 is not defined.<BR>Thank you.<BR>

  2. #2
    Join Date
    Dec 1969

    Default Where did you reference..

    .. the .vb file that contains the Class1 code?

  3. #3
    Join Date
    Dec 1969

    Default RE: Using Classes and Modules

    If you are using VS.NET, compile the class module and add a reference to the compiled file.<BR><BR>If you use Notepad, add this to the page directive:<BR>&#060;%@ Page Language="vb" Src="External.vb"&#062;<BR><BR>Create an instance of Class1 and call its mehtod.<BR><BR>If you add this to the page directive:<BR>&#060;%@ Page Language="vb" Src="External.vb" Inherits="NewNameSpace.Class1"%&#062;<BR><BR>You can call GETMyString() directly without creating an instance of Class1.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts