Usage of a class within script block
-
Hello everyone, I'm doing a little experimentation with some things. I've written a page without using a code behind and I'm trying to call a class (TextReader.vb) from within the block within the page, like so: <code> <%@ Page Language="vb"%> <script language="vb" runat=server> Private Sub Page_Load() <b>Dim Reader as New TextReader</b> Label1.Text = Reader.Extract("test.txt") End Sub I get a "Type Not Defined" error on the bolded line when I try to view the page. This probably has something to do with the compilation of the class, or I'm not implementing it correctly. Any ideas? Thanks in advance! ------------------- abort, retry, fail?
-
Hello everyone, I'm doing a little experimentation with some things. I've written a page without using a code behind and I'm trying to call a class (TextReader.vb) from within the block within the page, like so: <code> <%@ Page Language="vb"%> <script language="vb" runat=server> Private Sub Page_Load() <b>Dim Reader as New TextReader</b> Label1.Text = Reader.Extract("test.txt") End Sub I get a "Type Not Defined" error on the bolded line when I try to view the page. This probably has something to do with the compilation of the class, or I'm not implementing it correctly. Any ideas? Thanks in advance! ------------------- abort, retry, fail?
-
The TextReader class is inside the System.IO namespace. So you have to import it... Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!
Ah well that might be part of my problem. My TextReader is a custom class, so I guess renaming it would be in order so as to avoid any confusion. So now I'm doing this at the very beginning of the document and I'm still getting the same error:
<%@ Page Language="vb"%> <%@ Import Namespace="txtCMS.MyTextFileReader" %> Private Sub Page_Load() <b>Dim Reader as New MyTextFileReader</b> (BC30002: Type 'MyTextFileReader' is not defined.) Label1.Text = Reader.Extract("test.txt") End Sub
Any other ideas? ------------------- abort, retry, fail? -
Ah well that might be part of my problem. My TextReader is a custom class, so I guess renaming it would be in order so as to avoid any confusion. So now I'm doing this at the very beginning of the document and I'm still getting the same error:
<%@ Page Language="vb"%> <%@ Import Namespace="txtCMS.MyTextFileReader" %> Private Sub Page_Load() <b>Dim Reader as New MyTextFileReader</b> (BC30002: Type 'MyTextFileReader' is not defined.) Label1.Text = Reader.Extract("test.txt") End Sub
Any other ideas? ------------------- abort, retry, fail? -
Are you shure that you have refrences to the apropriate DLLs or/and you are importing the apropriate namespace (the one where your MyTextFileReader is)? Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!
I'm pretty sure, because when I do a test page using a codebehind page and use the same import path in the code behind instead of in it works fine. i.e. <code><%@ Import Namespace="txtCMS.TextFileReader" %></code> < -- (before <script>) does not work vs. <code>Imports txtCMS.TextFileReader</code> <-- (in code behind) works ------------------- abort, retry, fail?</x-turndown>
-
I'm pretty sure, because when I do a test page using a codebehind page and use the same import path in the code behind instead of in it works fine. i.e. <code><%@ Import Namespace="txtCMS.TextFileReader" %></code> < -- (before <script>) does not work vs. <code>Imports txtCMS.TextFileReader</code> <-- (in code behind) works ------------------- abort, retry, fail?</x-turndown>
-
Ah well that might be part of my problem. My TextReader is a custom class, so I guess renaming it would be in order so as to avoid any confusion. So now I'm doing this at the very beginning of the document and I'm still getting the same error:
<%@ Page Language="vb"%> <%@ Import Namespace="txtCMS.MyTextFileReader" %> Private Sub Page_Load() <b>Dim Reader as New MyTextFileReader</b> (BC30002: Type 'MyTextFileReader' is not defined.) Label1.Text = Reader.Extract("test.txt") End Sub
Any other ideas? ------------------- abort, retry, fail? -
Ah well that might be part of my problem. My TextReader is a custom class, so I guess renaming it would be in order so as to avoid any confusion. So now I'm doing this at the very beginning of the document and I'm still getting the same error:
<%@ Page Language="vb"%> <%@ Import Namespace="txtCMS.MyTextFileReader" %> Private Sub Page_Load() <b>Dim Reader as New MyTextFileReader</b> (BC30002: Type 'MyTextFileReader' is not defined.) Label1.Text = Reader.Extract("test.txt") End Sub
Any other ideas? ------------------- abort, retry, fail?