Use a partial class as an atribute of a normal class

Last post 06-01-2007 9:19 AM by rrmarriott. 2 replies.

Sort Posts:

  • Use a partial class as an atribute of a normal class

    06-01-2007, 5:33 AM
    • Loading...
    • ckhro
    • Joined on 02-08-2007, 11:01 AM
    • Posts 25

    Hello everyone.

    I have a WebForm that can be used as an UI for several aplication features.  To avoid endless and confusing conditionals and others I would like to create a class using some sort of Provider Pattern, so that de Page_Load looks something like this

    protected void Page_Load(object sender, EventArgs e){

          If( ! IsPostBack){

                    Entity entity = DataAcces.getEntity(Convert.toInt32(Session["EntityId"]));

                    EntityPageReader reader = GetProvider(entity);

                    reader.read();

           }

    }

     Wouldn't that be nice?

    The GetProvider(Entity entity) returns the correct reader based on my entity object state (ex: if it has been aproved be seccion Chief, etc) and the reader fills the information on the form.

    In order to do that my reader classes need to have access to the controls from my web page.

    How can I do that?  A class that is in App_Code to have an atribute that is a partial class?

    If my aspx file is:

           Default.aspx

    my codebehind

           Default.aspx.cs

    and my class declaration

    public partial class _Default : System.Web.UI.Page{

    }

    Then I would like to have something like

    public abstract class EntityPageReader {

           setPage(_Default default);               //NOTE THAT THIS IS INCORRECT.  IT'S EXACTLY WHAT I WANT TO KNOW.

    }

    Any ideas?  Is this possible?

    Thank you

    Filed under: ,
  • Re: Use a partial class as an atribute of a normal class

    06-01-2007, 9:04 AM
    • Loading...
    • bmains
    • Joined on 10-22-2004, 8:20 AM
    • Posts 5,055

    Hey,

    It seems like you should consider a custom base page class, which all your pages could inherit from, which you can create an abstract method to get the associated provider.  I think this is more along the lines of what you need, but not sure if I understand it correctly.

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: Use a partial class as an atribute of a normal class

    06-01-2007, 9:19 AM
    • Loading...
    • rrmarriott
    • Joined on 06-07-2006, 4:06 AM
    • Manchester, UK
    • Posts 78

    Hi,

    I think I understand what you are trying to do....If the explanation makes no sense then let me know!

    You need to acces the controls from your page in your reader classes? To do this, I would pass the Page.Controls collection to the GetProvider method as a new parameter, and hence into the specific reader class's constructor. From the Controls collection held in the reader class you can look up by id (which will have to be known by the reader class) each control you need to populate and populate it. All should be done by reference so that any controls you populate in your reader class should be populated on the form.

    Does that help?

    Rich

    Please mark any responses as Answers if they helped you solve your problem
Page 1 of 1 (3 items)
Microsoft Communities
Page view counter