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
Göran Andersson - 21 Jul 2007 20:26 GMT
> 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
[quoted text clipped - 4 lines]
> 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
[quoted text clipped - 12 lines]
>
> End Sub

Signature
Göran Andersson
_____
http://www.guffa.com
Mark Rae [MVP] - 21 Jul 2007 20:36 GMT
>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...?

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Brandon Gano - 21 Jul 2007 22:23 GMT
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.
>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
[quoted text clipped - 19 lines]
>
> End Sub
Mark Rae [MVP] - 21 Jul 2007 22:38 GMT
> 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...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Brandon Gano - 22 Jul 2007 00:23 GMT
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.
>> 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.
[quoted text clipped - 3 lines]
> required whilst still maintaining a single copy of the code - that would
> certainly be my preferred method...