Share VB code across multiple pages?

Discussion in 'ASP .Net' started by antonyliu2002@yahoo.com, Nov 18, 2005.

  1. Guest

    I am using ASP.NET 1.1.

    In my web application, multiple pages will be using the same functions.
    I am wondering if I can just pick out the shared code and save it in a
    separate file and then imports it in my webpages.

    Say if I save my VB functions in a file called mySharedCode.vb which
    has for example a Sub called "ConvertTextBoxData", how do I call this
    Sub in my page called page1.aspx?

    Thanks a lot!
     
    , Nov 18, 2005
    #1
    1. Advertising

  2. re:
    > how do I call this Sub in my page called page1.aspx?


    You don't.

    What you do is compile "SharedCode.vb" to an assembly,
    place the assembly in the /bin directory, and import your class's
    namespace into any aspx page you want to use it in.

    vbc /t:library /out:..\bin\SharedCode.dll SharedCode.vb /r:system.dll

    If you need to add more .net classes, add them like this:
    /r:system.dll /r:system.data.dll /r:system.xml.dll

    Then, import your namespace into your aspx page :

    <%@ Import Namespace="SharedCode" %>

    This assumes that your class's namespace is named SharedCode.


    Juan T. Llibre, ASP.NET MVP
    ASP.NET FAQ : http://asp.net.do/faq/
    ASPNETFAQ.COM : http://www.aspnetfaq.com/
    Foros de ASP.NET en Español : http://asp.net.do/foros/
    ======================================
    <> wrote in message
    news:...
    >I am using ASP.NET 1.1.
    >
    > In my web application, multiple pages will be using the same functions.
    > I am wondering if I can just pick out the shared code and save it in a
    > separate file and then imports it in my webpages.
    >
    > Say if I save my VB functions in a file called mySharedCode.vb which
    > has for example a Sub called "ConvertTextBoxData", how do I call this
    > Sub in my page called page1.aspx?
    >
    > Thanks a lot!
    >
     
    Juan T. Llibre, Nov 18, 2005
    #2
    1. Advertising

  3. Guest

    OK. thanks. But it's like pain in the butt for me to compile my VB
    code. When I tried doing that before, the system keeps saying that
    this library is missing, that dll file is not found.
     
    , Nov 18, 2005
    #3
  4. You have to know which assemblies you need to call.

    Just add any required .net assemblies:

    vbc /t:library /out:..\bin\SharedCode.dll SharedCode.vb /r:system.dll /r:system.data.dll

    etc.

    If it's a pain in the butt, you're doing it the wrong way... ;-)
    It's quite easy, actually.

    Use the class browser to find out what's where.



    Juan T. Llibre, ASP.NET MVP
    ASP.NET FAQ : http://asp.net.do/faq/
    ASPNETFAQ.COM : http://www.aspnetfaq.com/
    Foros de ASP.NET en Español : http://asp.net.do/foros/
    ======================================
    <> wrote in message
    news:...
    > OK. thanks. But it's like pain in the butt for me to compile my VB
    > code. When I tried doing that before, the system keeps saying that
    > this library is missing, that dll file is not found.
     
    Juan T. Llibre, Nov 18, 2005
    #4
  5. Juan can VS.NET do this for you?
    Patrick

    "Juan T. Llibre" <> wrote in message
    news:...
    > You have to know which assemblies you need to call.
    >
    > Just add any required .net assemblies:
    >
    > vbc /t:library /out:..\bin\SharedCode.dll SharedCode.vb /r:system.dll

    /r:system.data.dll
    >
    > etc.
    >
    > If it's a pain in the butt, you're doing it the wrong way... ;-)
    > It's quite easy, actually.
    >
    > Use the class browser to find out what's where.
    >
    >
    >
    > Juan T. Llibre, ASP.NET MVP
    > ASP.NET FAQ : http://asp.net.do/faq/
    > ASPNETFAQ.COM : http://www.aspnetfaq.com/
    > Foros de ASP.NET en Español : http://asp.net.do/foros/
    > ======================================
    > <> wrote in message
    > news:...
    > > OK. thanks. But it's like pain in the butt for me to compile my VB
    > > code. When I tried doing that before, the system keeps saying that
    > > this library is missing, that dll file is not found.

    >
    >
     
    Patrick.O.Ige, Nov 18, 2005
    #5
  6. No.

    VS.NET 2005 has a feature which could be useful,
    which is placing class files in the App_Code directory.

    They get compiled automatically, and can be referenced
    in aspx pages, but that's not quite the same.

    The ability to compile assemblies from the command-line is
    one of the most powerful features the .Net Framework offers.

    It makes the job of creating classes, and referencing them in aspx pages, a snap.

    After they're compiled, adding a reference to them in VS.NET
    lets you access all the classes, methods and properties with full intellisense.




    Juan T. Llibre, ASP.NET MVP
    ASP.NET FAQ : http://asp.net.do/faq/
    ASPNETFAQ.COM : http://www.aspnetfaq.com/
    Foros de ASP.NET en Español : http://asp.net.do/foros/
    ======================================
    "Patrick.O.Ige" <> wrote in message
    news:...
    > Juan can VS.NET do this for you?
    > Patrick


    > "Juan T. Llibre" <> wrote in message
    > news:...
    >> You have to know which assemblies you need to call.
    >>
    >> Just add any required .net assemblies:
    >>
    >> vbc /t:library /out:..\bin\SharedCode.dll SharedCode.vb /r:system.dll

    > /r:system.data.dll
    >>
    >> etc.
    >>
    >> If it's a pain in the butt, you're doing it the wrong way... ;-)
    >> It's quite easy, actually.
    >>
    >> Use the class browser to find out what's where.
    >>
    >>
    >>
    >> Juan T. Llibre, ASP.NET MVP
    >> ASP.NET FAQ : http://asp.net.do/faq/
    >> ASPNETFAQ.COM : http://www.aspnetfaq.com/
    >> Foros de ASP.NET en Español : http://asp.net.do/foros/
    >> ======================================
    >> <> wrote in message
    >> news:...
    >> > OK. thanks. But it's like pain in the butt for me to compile my VB
    >> > code. When I tried doing that before, the system keeps saying that
    >> > this library is missing, that dll file is not found.

    >>
    >>

    >
    >
     
    Juan T. Llibre, Nov 18, 2005
    #6
  7. Thx Juan
    Awesome Juan.
    Good Good.
    Reading through some books for ASPNET 2.0 for now.
    But will get my hands on it soon
    Patrick


    "Juan T. Llibre" <> wrote in message
    news:...
    > No.
    >
    > VS.NET 2005 has a feature which could be useful,
    > which is placing class files in the App_Code directory.
    >
    > They get compiled automatically, and can be referenced
    > in aspx pages, but that's not quite the same.
    >
    > The ability to compile assemblies from the command-line is
    > one of the most powerful features the .Net Framework offers.
    >
    > It makes the job of creating classes, and referencing them in aspx pages,

    a snap.
    >
    > After they're compiled, adding a reference to them in VS.NET
    > lets you access all the classes, methods and properties with full

    intellisense.
    >
    >
    >
    >
    > Juan T. Llibre, ASP.NET MVP
    > ASP.NET FAQ : http://asp.net.do/faq/
    > ASPNETFAQ.COM : http://www.aspnetfaq.com/
    > Foros de ASP.NET en Español : http://asp.net.do/foros/
    > ======================================
    > "Patrick.O.Ige" <> wrote in message
    > news:...
    > > Juan can VS.NET do this for you?
    > > Patrick

    >
    > > "Juan T. Llibre" <> wrote in message
    > > news:...
    > >> You have to know which assemblies you need to call.
    > >>
    > >> Just add any required .net assemblies:
    > >>
    > >> vbc /t:library /out:..\bin\SharedCode.dll SharedCode.vb /r:system.dll

    > > /r:system.data.dll
    > >>
    > >> etc.
    > >>
    > >> If it's a pain in the butt, you're doing it the wrong way... ;-)
    > >> It's quite easy, actually.
    > >>
    > >> Use the class browser to find out what's where.
    > >>
    > >>
    > >>
    > >> Juan T. Llibre, ASP.NET MVP
    > >> ASP.NET FAQ : http://asp.net.do/faq/
    > >> ASPNETFAQ.COM : http://www.aspnetfaq.com/
    > >> Foros de ASP.NET en Español : http://asp.net.do/foros/
    > >> ======================================
    > >> <> wrote in message
    > >> news:...
    > >> > OK. thanks. But it's like pain in the butt for me to compile my VB
    > >> > code. When I tried doing that before, the system keeps saying that
    > >> > this library is missing, that dll file is not found.
    > >>
    > >>

    > >
    > >

    >
    >
     
    Patrick.O.Ige, Nov 19, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan
    Replies:
    7
    Views:
    601
  2. Jheitmuller
    Replies:
    1
    Views:
    483
  3. Replies:
    14
    Views:
    1,733
    Juan T. Llibre
    Sep 29, 2005
  4. Adam Lipscombe
    Replies:
    8
    Views:
    1,139
  5. Saraswati lakki
    Replies:
    0
    Views:
    1,408
    Saraswati lakki
    Jan 6, 2012
Loading...

Share This Page