locked
reference the parent page from a user control in asp.net 2.0? RRS feed

  • Question

  • User626324527 posted

    In ASP.NET 1.x, every page has an explicit class name so if you have an aspx  name named MyPage,  it can be called inside a user control it contains by doing a cast:

    ((MyPage)this.Page).SomeFunction();

    It's not a good way to create such a dependency but sometimes necessary.  In ASP.NET 2.0, how to do this?  The page class name is not allowed in the child control as doing <% Reference Page="MyPage.aspx"%> in the child control results in a circular reference error during compile. 

    Tuesday, August 22, 2006 12:44 AM

All replies

  • User2032526919 posted

    Hi,

    see Understanding Page Inheritance in ASP.NET 2.0

    Basically you'd create a base class for your page into App_Code (exposing all needed functionality via the base class) and derive your page from it. UC could then cast Page to the base type and use it.

    Another way is to use Web Application Project Model (extenmsion to VS2005 by MS) which allows you to work as you worked with 1.x.

    Tuesday, August 22, 2006 2:17 AM
  • User626324527 posted

    Thanks a lot.  uh, forgot about the base class inthe App_Code folder option.  I'm reluctant to add an extra layer there since such a need is rarely common, that is, the page function that needs to be refrenced is different from page to page. 

    Still don't understand why MS favored the Web Site Project model over Web Application Project in VS 2005.

    Wednesday, August 23, 2006 11:42 AM