Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Usage of a class within script block

Usage of a class within script block

Scheduled Pinned Locked Moved ASP.NET
sysadmintoolshelpquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jszpila
    wrote on last edited by
    #1

    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?

    C 1 Reply Last reply
    0
    • J jszpila

      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?

      C Offline
      C Offline
      CWIZO
      wrote on last edited by
      #2

      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!

      J 1 Reply Last reply
      0
      • C CWIZO

        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!

        J Offline
        J Offline
        jszpila
        wrote on last edited by
        #3

        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?

        C M I 3 Replies Last reply
        0
        • J jszpila

          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?

          C Offline
          C Offline
          CWIZO
          wrote on last edited by
          #4

          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!

          J 1 Reply Last reply
          0
          • C CWIZO

            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!

            J Offline
            J Offline
            jszpila
            wrote on last edited by
            #5

            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>

            C 1 Reply Last reply
            0
            • J jszpila

              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>

              C Offline
              C Offline
              CWIZO
              wrote on last edited by
              #6

              Well sorry then I can't help you. Maybe if I had access to the whole code... but I am shure somebody will come with a solution;) Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

              1 Reply Last reply
              0
              • J jszpila

                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?

                M Offline
                M Offline
                minhpc_bk
                wrote on last edited by
                #7

                Hi there, Are you sure the name of the namespace is txtCMS.MyTextFileReader or simply txtCMS? Where do you define your custom class?

                1 Reply Last reply
                0
                • J jszpila

                  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?

                  I Offline
                  I Offline
                  Ista
                  wrote on last edited by
                  #8

                  jszpila wrote:

                  Dim Reader as New MyTextFileReader (BC30002: Type 'MyTextFileReader' is not defined.)

                  Well first of all Dim as a TextFileReader and import the namespace 1 line of code equals many bugs. So don't write any!!

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups