Codebehind Attribute and Different Paths

L

landers

Hi All,

I have created a vb file that inherits a System.Web.UI.Page. As I am
against duplicating source code, I have set the Codebehind attribute on all
my aspx pages in the same directory. This works a treat.

Now, I have a sub-directory full of aspx pages that I wish to point to this
wonderful vb file using the Codebehind attribute again. The designer errors
with "The class file '../basepage.vb' specified as the codebehind for
'default.aspx' could not be loaded. Make sure that the codebehind attribute
in the page or control directive properly references an existing code behind
file."

Ok, so the designer does not work for these pages. If I then debug the web
application and visit one of this pages in the sub-directory, it fires the
Page_Load event and runs my code and all is fine.

So, my question is how do I get the designer to work for these pages in the
sub-directory?

Landers
 
S

Scott Allen

I'd suggest not using this strategy as you'll be swimming upstream
against the tools, esepcially when it comes time to move to 2.0.

A better approach would be to put all of your common code into a base
class derived from System.Web.UI.Page, and then derive all your web
form pages from this custom base class. You'll be able to resuse your
code and still have tool support and flexibility to make changes.
 
L

landers

Thanks for your response. I have got it working now.

When I first tried I got the following error when trying to view the page in
a designer:

<<Error Message>>
The file could not be loaded into the Web Foms designer. Please correct the
following error and then try loading it again:

Type Abstract

Make sure all of the classes used in the page are built or references in the
project.
<<End Error Message>>

It turns out that you cannot use MustInherit on the base class. Also, you
must declare the base class as Public, as Friend just does not work.

Thanks again.
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top