creating classes

Discussion in 'ASP .Net' started by MagicKat, Jul 21, 2007.

  1. MagicKat

    MagicKat Guest

    I have moved my class files out of my web site and into a separate project,
    as recommended by other programmers. Now, however, I cannot reference
    anything like a label or a master page. I have imported Microsoft.Visual
    basic into the new project. What else am I missing?

    For instance, every asp page in the main project uses the following
    procedure, so I moved it to the shared project in order to share it. I have
    errors on the master page and label reference. Now I have to move it back
    so that the same procedure is in every page??? that doesn't seem very
    efficient to me. Thank you for your help.
    Public Sub SetMasterPage(Byval sPage as String, ByRef m as masterpage)

    Dim lblPageHeading As Label

    lblPageHeading = CType(m.FindControl("lblPageHeading"), Label)

    If Not lblPageHeading Is Nothing Then

    lblPageHeading.Text = sPage

    End If

    End Sub
     
    MagicKat, Jul 21, 2007
    #1
    1. Advertising

  2. MagicKat wrote:
    > I have moved my class files out of my web site and into a separate project,
    > as recommended by other programmers. Now, however, I cannot reference
    > anything like a label or a master page. I have imported Microsoft.Visual
    > basic into the new project. What else am I missing?
    >
    > For instance, every asp page in the main project uses the following
    > procedure, so I moved it to the shared project in order to share it. I have
    > errors on the master page and label reference.


    Standard question #2:
    What error message do you get?

    > Now I have to move it back
    > so that the same procedure is in every page??? that doesn't seem very
    > efficient to me. Thank you for your help.
    > Public Sub SetMasterPage(Byval sPage as String, ByRef m as masterpage)
    >
    > Dim lblPageHeading As Label
    >
    > lblPageHeading = CType(m.FindControl("lblPageHeading"), Label)
    >
    > If Not lblPageHeading Is Nothing Then
    >
    > lblPageHeading.Text = sPage
    >
    > End If
    >
    > End Sub
    >
    >
    >



    --
    Göran Andersson
    _____
    http://www.guffa.com
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Jul 21, 2007
    #2
    1. Advertising

  3. "MagicKat" <> wrote in message
    news:...

    >I have moved my class files out of my web site and into a separate project,
    >as recommended by other programmers.


    ??? Who on earth advised you to do that...???

    > What else am I missing?


    Well, since you've now moved your app's functionality (i.e. its classes)
    into a separate project, you'll need to add a reference to it... Have you
    done that...?


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Jul 21, 2007
    #3
  4. MagicKat

    Brandon Gano Guest

    It looks like the code you have moved to another project is directly related
    to your website output. Unless you need to use the code in more than one web
    project, it would be better to keep this kind of code in the App_Code
    folder.

    If the code will be used in more than one web project (database code, for
    example), it should absolutely be moved to its own class library.

    Regardless of where the code lies, I think what you want to do is override
    the default Page class. Something like this (forgive the C#, my VB is a bit
    rusty):

    public class MyPage : System.Web.UI.Page
    {
    public Label lblPageHeading;
    // ...

    protected override void OnLoad(EventArgs e)
    {
    // ...
    }
    }

    Then in your code-behind files, inherit from MyPage instead of
    System.Web.UI.Page. For example:

    public partial class _Default : MyPage
    {
    // ...
    }

    All of your pages will then inherit the properties and methods from MyPage.


    "MagicKat" <> wrote in message
    news:...
    >I have moved my class files out of my web site and into a separate project,
    >as recommended by other programmers. Now, however, I cannot reference
    >anything like a label or a master page. I have imported Microsoft.Visual
    >basic into the new project. What else am I missing?
    >
    > For instance, every asp page in the main project uses the following
    > procedure, so I moved it to the shared project in order to share it. I
    > have errors on the master page and label reference. Now I have to move it
    > back so that the same procedure is in every page??? that doesn't seem very
    > efficient to me. Thank you for your help.
    > Public Sub SetMasterPage(Byval sPage as String, ByRef m as masterpage)
    >
    > Dim lblPageHeading As Label
    >
    > lblPageHeading = CType(m.FindControl("lblPageHeading"), Label)
    >
    > If Not lblPageHeading Is Nothing Then
    >
    > lblPageHeading.Text = sPage
    >
    > End If
    >
    > End Sub
    >
    >
    >
     
    Brandon Gano, Jul 21, 2007
    #4
  5. "Brandon Gano" <> wrote in message
    news:...

    > If the code will be used in more than one web project (database code, for
    > example), it should absolutely be moved to its own class library.


    Or moved into a source code repository e.g. Visual SourceSafe from where the
    individual classes can be shared into other projects as and when required
    whilst still maintaining a single copy of the code - that would certainly be
    my preferred method...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Jul 21, 2007
    #5
  6. MagicKat

    Brandon Gano Guest

    Yes, that would probably work fine for this project.

    One benefit of using class libraries is that you can make changes to
    database code or other business logic without having to re-compile/publish
    the web project (in most cases). You would simply need to drop the new dll
    into the project's bin folder. This may be overkill for most smaller
    projects, but it becomes critical in larger-scale projects.


    "Mark Rae [MVP]" <> wrote in message
    news:uU6N$...
    > "Brandon Gano" <> wrote in message
    > news:...
    >
    >> If the code will be used in more than one web project (database code, for
    >> example), it should absolutely be moved to its own class library.

    >
    > Or moved into a source code repository e.g. Visual SourceSafe from where
    > the individual classes can be shared into other projects as and when
    > required whilst still maintaining a single copy of the code - that would
    > certainly be my preferred method...
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    Brandon Gano, Jul 22, 2007
    #6
    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. David

    Classes within classes

    David, Jul 21, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,952
    David
    Jul 22, 2005
  2. lonelyplanet999
    Replies:
    1
    Views:
    2,226
    VisionSet
    Nov 13, 2003
  3. Carfield Yim
    Replies:
    1
    Views:
    1,438
    Andrew Thompson
    May 31, 2004
  4. Razvan
    Replies:
    11
    Views:
    921
    Andrew Thompson
    Jul 17, 2004
  5. Razvan
    Replies:
    5
    Views:
    11,311
    Dale King
    Jul 27, 2004
Loading...

Share This Page