page to control in 2.0

J

jhcorey

This is an ASP.NET 2.0 question.

In 1.0, common techniques for communicating between a page and the
controls on it
depended on being able to declare variables of the page and control
types.
For example, if I had a page called MyPage.aspx, then I could declare a
variable
of type MyPage in my user control code. Typically I would have a
namespace with the same name as my project.

I don't know how to do this in 2.0. It seems to have something to do
with the page and user control classes being partial classes -- I can
declare variables
of any 'normal' classes in the project.

No doubt there's a simple solution.
 
S

Scott Allen

In 1.x the code-behind class for the control and the code-behind class
for the Page were visible to each other because both classes compiled
to the same assembly.

In 2.0, user control and Page types are not visible to each other by
default, unless you use an @ Reference directive (or an @ Register
directive for a control).

Here are a couple posts describing different scenarios in this area:
http://odetocode.com/Blogs/scott/archive/2005/08/01/2030.aspx
http://odetocode.com/Blogs/scott/archive/2005/06/30/1889.aspx

The problem you may run into is a circular reference if both the page
and control want to reference each other. If this is a case I'd define
an interface for your page in App_Code or another class library that
the Page derived class implements. The control can then talk to the
page through the interface.

HTH,
 

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

Top