Problem with user control on ASP.NET 2.0

A

Ahmed

Is it possible for a user control on a webform to access the base class(another
webfrom) of the host page ?

e.g my code does something like this:


ChildPage inherits from ParentPage

and a function in the code behind of a user control hosted on ChildPage does
this


ParentPage p = (ParentPage)this.Page;
p.SomeFunction();


This used to work fine on ASP.NET 1.1 but gives errors on ASP.NET 2.0 beta
2 june ctp. Most probably this is due to the new compilation model. Any solutions
or workaround?

Also is it possile to just access the host page in the code beside of a user
control, something like this:

(based on the above scenario)

ChildPage p = this.Page;

p.SomeOtherFunction();

would asp.net 2.0 complain about this too and if yes how to do something
like this in 2.0 ?

-Ahmed
 
S

Steven Cheng[MSFT]

Hi Ahmed,

Welcome to MSDN newsgroup.
As for the casting page error you mentioned, here are some of my
understanding:

1. For class casting, as long as the underlying instance is of the certain
class, we can surely cast it to that type's reference. I suggest you first
using the object.GetType().ToString() to dump out the UserControl.Page's
actual type to see whether that's your expected one.

2. As for the parent/ child page, do you mean the normal class inheritance
in c# , just like:

class ParentPage
{
..........
}
class ChildPage: Parent Page
{
........
}

or the MasterPage in ASP.NET 2.0? If you're using the MasterPage, I'm
afraid you can't using the type casting because MasterPage isn't
implemented by simplly using the .NET class's inheritance. The concrete
page class isn't acutally derived from the MasterPage.

In addition, for ASP.NET 2.0 problems, I'd suggest you try posting in the
MSDN web forum since there're many experienced community members or ASP.NET
develop team's guys there.

http://forums.microsoft.com/msdn/

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Hi Steven

I am developing an asp.net application using c# and asp.net 2.0 beta 2. I
started developing this page usign beta1. In beta 1 I have written some code
in Page_LoadComplete(object sender, EventArgs e) events of page. It was
working fine. But after I installed beta 2.0 Page_LoadComplete events is not
firing at all. Can u guide me how can I achieve this goal?

Thankx in advance.
Shailesh.
 

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,780
Messages
2,569,608
Members
45,249
Latest member
KattieCort

Latest Threads

Top