creating classes

M

MagicKat

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
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

MagicKat said:
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?
 
M

Mark Rae [MVP]

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...?
 
B

Brandon Gano

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.
 
M

Mark Rae [MVP]

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...
 
B

Brandon Gano

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top