HTML Page Shell/Template and BasePage Class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Maghen

    HTML Page Shell/Template and BasePage Class

    I have a site where most of the pages will have a common "shell" or layout. There will be an outer table which will hold HTML elements but which will *also* hold UserControls (Global Nav, etc.). Right now, all of the HTML and the @ Register directives for the shell's UserControls are copied onto each and every .ASCX page on the site

    I find this kind of frustrating because it means that I have to change many files whenever I want to make chages to the actual framework of the shell itself (as opposed to the UserControls embedded *in* the shell)

    If the shell contains UserContols which need to be accessible from individual page methods, etc., I can't hink of how to do this. Right now, all of the pages on the site *do* derive from a common "BasePage" class which inherits from "Page" but I don't really know how I could use that to do this.

    Help???
  • Steven Cheng[MSFT]

    #2
    RE: HTML Page Shell/Template and BasePage Class

    Hi,

    From your description, you've defined a certain base page class which
    contains some common UI layout and shells and most pages in your web
    application will derived from it. Now, you found that
    1. you had to write those @Register diretives in every derived page's page
    template
    2. Not sure how to retireve a certain UserControls and do some operations
    on it in a certain page's function, yes?

    As for these problems, here are my suggestions:
    1. When want to add some common content( UI layout) in most pages which has
    a common basepage, we can use the serverside include file to contains those
    common page templates rather than write them(such as diretives or html
    sources in each page). Here is the reference in MSDN:
    #Server-Side Include Directive Syntax
    Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.

    edirectivesynta x.asp?frame=tru e

    2. As for the second problem that retrieving a usercontrol on the page in a
    certain function(base page or derived page). That does be a pain, because
    in ASP.NET, if we want to retrieve a control's instance in page's control
    collection, we need to know its exact postion in the page's control
    hierarchy. And then use FindControl method to retrieve it via id. That 'll
    be abit complex since you've defined many UserControls on a page and need
    to retireve them at runtime from the page's control hierarchy. You need to
    know what's the UserControl's parent server control and find it from its
    collecton. You can turn on the page's trace
    <@Page Trace="true" ..>
    To have a look at the certain page's Control tree so as to confirm this.

    In addtion, here are some certain tech articles in MSDN on designing a
    page controller( a common base page class) in asp.net web app.

    #Page Controller
    Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.

    p?frame=true

    Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.

    p?frame=true

    Also, in the ASP.NET's new release (Whidbey, there is a new featrue called
    "Master Page") , it 'll much improve our capability on designing a certain
    common page pages not only on function but also on UI inheritance.

    #Master Pages in ASP.NET Whidbey
    Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.

    rame=true

    Hope helps. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

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

    Get Preview at ASP.NET whidbey
    Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.









    Comment

    • Steven Cheng[MSFT]

      #3
      RE: HTML Page Shell/Template and BasePage Class

      Hi,

      Have you had a chance to check out the suggestions in my last reply or have
      you got any further ideas on this issue? If you have anything unclear or if
      there're anything else we can help, please feel free to post here. Thanks.

      Regards,

      Steven Cheng
      Microsoft Online Support

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

      Get Preview at ASP.NET whidbey
      Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.


      Comment

      Working...