Extending ASP.net pages using Partial Classes

Discussion in 'ASP .Net' started by =?Utf-8?B?RmF0IEVsdmlz?=, Jun 15, 2006.

  1. I'd like to extend some of my Asp.net pages by using Partial Classes.

    Example ASP.Net Page:
    public partial class Admin_Customer : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    Data_List();
    }
    }

    I'd like to add (in another file):
    public partial class Admin_Customer
    {
    protected void Data_List()
    { . . code . . .}
    }

    Each time I complie the page cannot see the Data_List() method ?
    Error Message "The name Data_List does not exist in the current contact".

    I've been scouring the web all morning with no sucess, tried a few things
    like putting them in the same namespace but that does not seem to help. Also
    given them the same inherit statement.

    Any suggestions Please ?
     
    =?Utf-8?B?RmF0IEVsdmlz?=, Jun 15, 2006
    #1
    1. Advertising

  2. You'll need to place the source file extending the class in the App_Code directory.

    You cannot extend a partial class in a page's code-behind source
    in a different page's code-behind source.

    Try it, and view the complete class with Visual Studio's Class View feature.




    Juan T. Llibre, asp.net MVP
    aspnetfaq.com : http://www.aspnetfaq.com/
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ===================================
    "Fat Elvis" <> wrote in message
    news:...
    > I'd like to extend some of my Asp.net pages by using Partial Classes.
    >
    > Example ASP.Net Page:
    > public partial class Admin_Customer : System.Web.UI.Page
    > {
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > Data_List();
    > }
    > }
    >
    > I'd like to add (in another file):
    > public partial class Admin_Customer
    > {
    > protected void Data_List()
    > { . . code . . .}
    > }
    >
    > Each time I complie the page cannot see the Data_List() method ?
    > Error Message "The name Data_List does not exist in the current contact".
    >
    > I've been scouring the web all morning with no sucess, tried a few things
    > like putting them in the same namespace but that does not seem to help. Also
    > given them the same inherit statement.
    >
    > Any suggestions Please ?
     
    Juan T. Llibre, Jun 15, 2006
    #2
    1. Advertising

  3. Juan,

    The "new" partial class is in the \App_Code\PartialClasses.cs file.

    The .aspx page (and .aspx.cs) is in the root.

    Any other ideas ?

    Thx, Lee.


    "Juan T. Llibre" wrote:

    > You'll need to place the source file extending the class in the App_Code directory.
    >
    > You cannot extend a partial class in a page's code-behind source
    > in a different page's code-behind source.
    >
    > Try it, and view the complete class with Visual Studio's Class View feature.
    >
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > aspnetfaq.com : http://www.aspnetfaq.com/
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ===================================
    > "Fat Elvis" <> wrote in message
    > news:...
    > > I'd like to extend some of my Asp.net pages by using Partial Classes.
    > >
    > > Example ASP.Net Page:
    > > public partial class Admin_Customer : System.Web.UI.Page
    > > {
    > > protected void Page_Load(object sender, EventArgs e)
    > > {
    > > Data_List();
    > > }
    > > }
    > >
    > > I'd like to add (in another file):
    > > public partial class Admin_Customer
    > > {
    > > protected void Data_List()
    > > { . . code . . .}
    > > }
    > >
    > > Each time I complie the page cannot see the Data_List() method ?
    > > Error Message "The name Data_List does not exist in the current contact".
    > >
    > > I've been scouring the web all morning with no sucess, tried a few things
    > > like putting them in the same namespace but that does not seem to help. Also
    > > given them the same inherit statement.
    > >
    > > Any suggestions Please ?

    >
    >
    >
     
    =?Utf-8?B?RmF0IEVsdmlz?=, Jun 15, 2006
    #3
  4. Are both partial classes within the same namespace ?

    i.e.,

    in one file :
    Namespace somenamespace
    public partial class Admin_Customer

    in PartialClasses.cs :
    Namespace somenamespace
    public partial class Admin_Customer




    Juan T. Llibre, asp.net MVP
    aspnetfaq.com : http://www.aspnetfaq.com/
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ===================================
    "Fat Elvis" <> wrote in message
    news:...
    > Juan,
    >
    > The "new" partial class is in the \App_Code\PartialClasses.cs file.
    >
    > The .aspx page (and .aspx.cs) is in the root.
    > Any other ideas ?
    >
    > Thx, Lee.



    > "Juan T. Llibre" wrote:
    >
    >> You'll need to place the source file extending the class in the App_Code directory.
    >>
    >> You cannot extend a partial class in a page's code-behind source
    >> in a different page's code-behind source.
    >>
    >> Try it, and view the complete class with Visual Studio's Class View feature.
    >>
    >>
    >>
    >>
    >> Juan T. Llibre, asp.net MVP
    >> aspnetfaq.com : http://www.aspnetfaq.com/
    >> asp.net faq : http://asp.net.do/faq/
    >> foros de asp.net, en español : http://asp.net.do/foros/
    >> ===================================
    >> "Fat Elvis" <> wrote in message
    >> news:...
    >> > I'd like to extend some of my Asp.net pages by using Partial Classes.
    >> >
    >> > Example ASP.Net Page:
    >> > public partial class Admin_Customer : System.Web.UI.Page
    >> > {
    >> > protected void Page_Load(object sender, EventArgs e)
    >> > {
    >> > Data_List();
    >> > }
    >> > }
    >> >
    >> > I'd like to add (in another file):
    >> > public partial class Admin_Customer
    >> > {
    >> > protected void Data_List()
    >> > { . . code . . .}
    >> > }
    >> >
    >> > Each time I complie the page cannot see the Data_List() method ?
    >> > Error Message "The name Data_List does not exist in the current contact".
    >> >
    >> > I've been scouring the web all morning with no sucess, tried a few things
    >> > like putting them in the same namespace but that does not seem to help. Also
    >> > given them the same inherit statement.
    >> >
    >> > Any suggestions Please ?

    >>
    >>
    >>
     
    Juan T. Llibre, Jun 15, 2006
    #4
  5. Yep.

    I tried that and it causes a different error.

    Lee :eek:(

    "Juan T. Llibre" wrote:

    > Are both partial classes within the same namespace ?
    >
    > i.e.,
    >
    > in one file :
    > Namespace somenamespace
    > public partial class Admin_Customer
    >
    > in PartialClasses.cs :
    > Namespace somenamespace
    > public partial class Admin_Customer
    >
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > aspnetfaq.com : http://www.aspnetfaq.com/
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ===================================
    > "Fat Elvis" <> wrote in message
    > news:...
    > > Juan,
    > >
    > > The "new" partial class is in the \App_Code\PartialClasses.cs file.
    > >
    > > The .aspx page (and .aspx.cs) is in the root.
    > > Any other ideas ?
    > >
    > > Thx, Lee.

    >
    >
    > > "Juan T. Llibre" wrote:
    > >
    > >> You'll need to place the source file extending the class in the App_Code directory.
    > >>
    > >> You cannot extend a partial class in a page's code-behind source
    > >> in a different page's code-behind source.
    > >>
    > >> Try it, and view the complete class with Visual Studio's Class View feature.
    > >>
    > >>
    > >>
    > >>
    > >> Juan T. Llibre, asp.net MVP
    > >> aspnetfaq.com : http://www.aspnetfaq.com/
    > >> asp.net faq : http://asp.net.do/faq/
    > >> foros de asp.net, en español : http://asp.net.do/foros/
    > >> ===================================
    > >> "Fat Elvis" <> wrote in message
    > >> news:...
    > >> > I'd like to extend some of my Asp.net pages by using Partial Classes.
    > >> >
    > >> > Example ASP.Net Page:
    > >> > public partial class Admin_Customer : System.Web.UI.Page
    > >> > {
    > >> > protected void Page_Load(object sender, EventArgs e)
    > >> > {
    > >> > Data_List();
    > >> > }
    > >> > }
    > >> >
    > >> > I'd like to add (in another file):
    > >> > public partial class Admin_Customer
    > >> > {
    > >> > protected void Data_List()
    > >> > { . . code . . .}
    > >> > }
    > >> >
    > >> > Each time I complie the page cannot see the Data_List() method ?
    > >> > Error Message "The name Data_List does not exist in the current contact".
    > >> >
    > >> > I've been scouring the web all morning with no sucess, tried a few things
    > >> > like putting them in the same namespace but that does not seem to help. Also
    > >> > given them the same inherit statement.
    > >> >
    > >> > Any suggestions Please ?
    > >>
    > >>
    > >>

    >
    >
    >
     
    =?Utf-8?B?RmF0IEVsdmlz?=, Jun 15, 2006
    #5
  6. Try this :

    Create a new website, with a default.aspx and a default.aspx.cs.

    Leave the default.aspx and the default.aspx.cs pages as they are.
    Create an App_Code directory and create a source file named "Default.cs" in it.

    Substitute the following code for the code in Default.cs :

    ----

    public partial class _Default : System.Web.UI.Page
    {
    public _Default()
    {
    int m_MyProperty;}
    // This is the property block.
    public int MyProperty
    {
    // Returns the value of m_MyProperty.
    get
    {
    return m_MyProperty;
    }
    set
    {
    // Checks if a valid value is being
    // assigned to the property.
    if (value > 5)
    {
    //
    //TO DO
    //
    }
    else
    {
    m_MyProperty = value;
    }
    }
    }

    ----

    Now, use the Class View feature in Visual Studio and highlight the _Default partial class.

    You will see the property MyProperty listed for the
    _Default partial class...which inherits from System.Web.UI.Page.

    Congratulations!
    You have just extended the partial class _Default from the source file "Default.cs".

    Adapt the example to any other extension you want to add to _Default,
    by adding properties or methods to Default.cs in the APp_Code directory.



    Juan T. Llibre, asp.net MVP
    aspnetfaq.com : http://www.aspnetfaq.com/
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ===================================
    "Fat Elvis" <> wrote in message
    news:...
    > Yep.
    >
    > I tried that and it causes a different error.
    >
    > Lee :eek:(
    >
    > "Juan T. Llibre" wrote:
    >
    >> Are both partial classes within the same namespace ?
    >>
    >> i.e.,
    >>
    >> in one file :
    >> Namespace somenamespace
    >> public partial class Admin_Customer
    >>
    >> in PartialClasses.cs :
    >> Namespace somenamespace
    >> public partial class Admin_Customer
    >>
    >>
    >>
    >>
    >> Juan T. Llibre, asp.net MVP
    >> aspnetfaq.com : http://www.aspnetfaq.com/
    >> asp.net faq : http://asp.net.do/faq/
    >> foros de asp.net, en español : http://asp.net.do/foros/
    >> ===================================
    >> "Fat Elvis" <> wrote in message
    >> news:...
    >> > Juan,
    >> >
    >> > The "new" partial class is in the \App_Code\PartialClasses.cs file.
    >> >
    >> > The .aspx page (and .aspx.cs) is in the root.
    >> > Any other ideas ?
    >> >
    >> > Thx, Lee.

    >>
    >>
    >> > "Juan T. Llibre" wrote:
    >> >
    >> >> You'll need to place the source file extending the class in the App_Code directory.
    >> >>
    >> >> You cannot extend a partial class in a page's code-behind source
    >> >> in a different page's code-behind source.
    >> >>
    >> >> Try it, and view the complete class with Visual Studio's Class View feature.
    >> >>
    >> >>
    >> >>
    >> >>
    >> >> Juan T. Llibre, asp.net MVP
    >> >> aspnetfaq.com : http://www.aspnetfaq.com/
    >> >> asp.net faq : http://asp.net.do/faq/
    >> >> foros de asp.net, en español : http://asp.net.do/foros/
    >> >> ===================================
    >> >> "Fat Elvis" <> wrote in message
    >> >> news:...
    >> >> > I'd like to extend some of my Asp.net pages by using Partial Classes.
    >> >> >
    >> >> > Example ASP.Net Page:
    >> >> > public partial class Admin_Customer : System.Web.UI.Page
    >> >> > {
    >> >> > protected void Page_Load(object sender, EventArgs e)
    >> >> > {
    >> >> > Data_List();
    >> >> > }
    >> >> > }
    >> >> >
    >> >> > I'd like to add (in another file):
    >> >> > public partial class Admin_Customer
    >> >> > {
    >> >> > protected void Data_List()
    >> >> > { . . code . . .}
    >> >> > }
    >> >> >
    >> >> > Each time I complie the page cannot see the Data_List() method ?
    >> >> > Error Message "The name Data_List does not exist in the current contact".
    >> >> >
    >> >> > I've been scouring the web all morning with no sucess, tried a few things
    >> >> > like putting them in the same namespace but that does not seem to help. Also
    >> >> > given them the same inherit statement.
    >> >> >
    >> >> > Any suggestions Please ?
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
     
    Juan T. Llibre, Jun 15, 2006
    #6
  7. Juan,

    Works a treat.

    However I cannot use the "MyProperty" property from the Page_Load event in
    the original code behind class - this is what I want to do.

    The error is "The name 'MyProperty' does not exist in the current context."

    Same goes for methods.

    Lee :eek:(

    "Juan T. Llibre" wrote:

    > Try this :
    >
    > Create a new website, with a default.aspx and a default.aspx.cs.
    >
    > Leave the default.aspx and the default.aspx.cs pages as they are.
    > Create an App_Code directory and create a source file named "Default.cs" in it.
    >
    > Substitute the following code for the code in Default.cs :
    >
    > ----
    >
    > public partial class _Default : System.Web.UI.Page
    > {
    > public _Default()
    > {
    > int m_MyProperty;}
    > // This is the property block.
    > public int MyProperty
    > {
    > // Returns the value of m_MyProperty.
    > get
    > {
    > return m_MyProperty;
    > }
    > set
    > {
    > // Checks if a valid value is being
    > // assigned to the property.
    > if (value > 5)
    > {
    > //
    > //TO DO
    > //
    > }
    > else
    > {
    > m_MyProperty = value;
    > }
    > }
    > }
    >
    > ----
    >
    > Now, use the Class View feature in Visual Studio and highlight the _Default partial class.
    >
    > You will see the property MyProperty listed for the
    > _Default partial class...which inherits from System.Web.UI.Page.
    >
    > Congratulations!
    > You have just extended the partial class _Default from the source file "Default.cs".
    >
    > Adapt the example to any other extension you want to add to _Default,
    > by adding properties or methods to Default.cs in the APp_Code directory.
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > aspnetfaq.com : http://www.aspnetfaq.com/
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ===================================
    > "Fat Elvis" <> wrote in message
    > news:...
    > > Yep.
    > >
    > > I tried that and it causes a different error.
    > >
    > > Lee :eek:(
    > >
    > > "Juan T. Llibre" wrote:
    > >
    > >> Are both partial classes within the same namespace ?
    > >>
    > >> i.e.,
    > >>
    > >> in one file :
    > >> Namespace somenamespace
    > >> public partial class Admin_Customer
    > >>
    > >> in PartialClasses.cs :
    > >> Namespace somenamespace
    > >> public partial class Admin_Customer
    > >>
    > >>
    > >>
    > >>
    > >> Juan T. Llibre, asp.net MVP
    > >> aspnetfaq.com : http://www.aspnetfaq.com/
    > >> asp.net faq : http://asp.net.do/faq/
    > >> foros de asp.net, en español : http://asp.net.do/foros/
    > >> ===================================
    > >> "Fat Elvis" <> wrote in message
    > >> news:...
    > >> > Juan,
    > >> >
    > >> > The "new" partial class is in the \App_Code\PartialClasses.cs file.
    > >> >
    > >> > The .aspx page (and .aspx.cs) is in the root.
    > >> > Any other ideas ?
    > >> >
    > >> > Thx, Lee.
    > >>
    > >>
    > >> > "Juan T. Llibre" wrote:
    > >> >
    > >> >> You'll need to place the source file extending the class in the App_Code directory.
    > >> >>
    > >> >> You cannot extend a partial class in a page's code-behind source
    > >> >> in a different page's code-behind source.
    > >> >>
    > >> >> Try it, and view the complete class with Visual Studio's Class View feature.
    > >> >>
    > >> >>
    > >> >>
    > >> >>
    > >> >> Juan T. Llibre, asp.net MVP
    > >> >> aspnetfaq.com : http://www.aspnetfaq.com/
    > >> >> asp.net faq : http://asp.net.do/faq/
    > >> >> foros de asp.net, en español : http://asp.net.do/foros/
    > >> >> ===================================
    > >> >> "Fat Elvis" <> wrote in message
    > >> >> news:...
    > >> >> > I'd like to extend some of my Asp.net pages by using Partial Classes.
    > >> >> >
    > >> >> > Example ASP.Net Page:
    > >> >> > public partial class Admin_Customer : System.Web.UI.Page
    > >> >> > {
    > >> >> > protected void Page_Load(object sender, EventArgs e)
    > >> >> > {
    > >> >> > Data_List();
    > >> >> > }
    > >> >> > }
    > >> >> >
    > >> >> > I'd like to add (in another file):
    > >> >> > public partial class Admin_Customer
    > >> >> > {
    > >> >> > protected void Data_List()
    > >> >> > { . . code . . .}
    > >> >> > }
    > >> >> >
    > >> >> > Each time I complie the page cannot see the Data_List() method ?
    > >> >> > Error Message "The name Data_List does not exist in the current contact".
    > >> >> >
    > >> >> > I've been scouring the web all morning with no sucess, tried a few things
    > >> >> > like putting them in the same namespace but that does not seem to help. Also
    > >> >> > given them the same inherit statement.
    > >> >> >
    > >> >> > Any suggestions Please ?
    > >> >>
    > >> >>
    > >> >>
    > >>
    > >>
    > >>

    >
    >
    >
    >
     
    =?Utf-8?B?RmF0IEVsdmlz?=, Jun 16, 2006
    #7
  8. Does Juan or anyone else have any ideas here ?

    Thx, Lee.



    "Fat Elvis" wrote:

    > Juan,
    >
    > Works a treat.
    >
    > However I cannot use the "MyProperty" property from the Page_Load event in
    > the original code behind class - this is what I want to do.
    >
    > The error is "The name 'MyProperty' does not exist in the current context."
    >
    > Same goes for methods.
    >
    > Lee :eek:(
    >
    > "Juan T. Llibre" wrote:
    >
    > > Try this :
    > >
    > > Create a new website, with a default.aspx and a default.aspx.cs.
    > >
    > > Leave the default.aspx and the default.aspx.cs pages as they are.
    > > Create an App_Code directory and create a source file named "Default.cs" in it.
    > >
    > > Substitute the following code for the code in Default.cs :
    > >
    > > ----
    > >
    > > public partial class _Default : System.Web.UI.Page
    > > {
    > > public _Default()
    > > {
    > > int m_MyProperty;}
    > > // This is the property block.
    > > public int MyProperty
    > > {
    > > // Returns the value of m_MyProperty.
    > > get
    > > {
    > > return m_MyProperty;
    > > }
    > > set
    > > {
    > > // Checks if a valid value is being
    > > // assigned to the property.
    > > if (value > 5)
    > > {
    > > //
    > > //TO DO
    > > //
    > > }
    > > else
    > > {
    > > m_MyProperty = value;
    > > }
    > > }
    > > }
    > >
    > > ----
    > >
    > > Now, use the Class View feature in Visual Studio and highlight the _Default partial class.
    > >
    > > You will see the property MyProperty listed for the
    > > _Default partial class...which inherits from System.Web.UI.Page.
    > >
    > > Congratulations!
    > > You have just extended the partial class _Default from the source file "Default.cs".
    > >
    > > Adapt the example to any other extension you want to add to _Default,
    > > by adding properties or methods to Default.cs in the APp_Code directory.
    > >
    > >
    > >
    > > Juan T. Llibre, asp.net MVP
    > > aspnetfaq.com : http://www.aspnetfaq.com/
    > > asp.net faq : http://asp.net.do/faq/
    > > foros de asp.net, en español : http://asp.net.do/foros/
    > > ===================================
    > > "Fat Elvis" <> wrote in message
    > > news:...
    > > > Yep.
    > > >
    > > > I tried that and it causes a different error.
    > > >
    > > > Lee :eek:(
    > > >
    > > > "Juan T. Llibre" wrote:
    > > >
    > > >> Are both partial classes within the same namespace ?
    > > >>
    > > >> i.e.,
    > > >>
    > > >> in one file :
    > > >> Namespace somenamespace
    > > >> public partial class Admin_Customer
    > > >>
    > > >> in PartialClasses.cs :
    > > >> Namespace somenamespace
    > > >> public partial class Admin_Customer
    > > >>
    > > >>
    > > >>
    > > >>
    > > >> Juan T. Llibre, asp.net MVP
    > > >> aspnetfaq.com : http://www.aspnetfaq.com/
    > > >> asp.net faq : http://asp.net.do/faq/
    > > >> foros de asp.net, en español : http://asp.net.do/foros/
    > > >> ===================================
    > > >> "Fat Elvis" <> wrote in message
    > > >> news:...
    > > >> > Juan,
    > > >> >
    > > >> > The "new" partial class is in the \App_Code\PartialClasses.cs file.
    > > >> >
    > > >> > The .aspx page (and .aspx.cs) is in the root.
    > > >> > Any other ideas ?
    > > >> >
    > > >> > Thx, Lee.
    > > >>
    > > >>
    > > >> > "Juan T. Llibre" wrote:
    > > >> >
    > > >> >> You'll need to place the source file extending the class in the App_Code directory.
    > > >> >>
    > > >> >> You cannot extend a partial class in a page's code-behind source
    > > >> >> in a different page's code-behind source.
    > > >> >>
    > > >> >> Try it, and view the complete class with Visual Studio's Class View feature.
    > > >> >>
    > > >> >>
    > > >> >>
    > > >> >>
    > > >> >> Juan T. Llibre, asp.net MVP
    > > >> >> aspnetfaq.com : http://www.aspnetfaq.com/
    > > >> >> asp.net faq : http://asp.net.do/faq/
    > > >> >> foros de asp.net, en español : http://asp.net.do/foros/
    > > >> >> ===================================
    > > >> >> "Fat Elvis" <> wrote in message
    > > >> >> news:...
    > > >> >> > I'd like to extend some of my Asp.net pages by using Partial Classes.
    > > >> >> >
    > > >> >> > Example ASP.Net Page:
    > > >> >> > public partial class Admin_Customer : System.Web.UI.Page
    > > >> >> > {
    > > >> >> > protected void Page_Load(object sender, EventArgs e)
    > > >> >> > {
    > > >> >> > Data_List();
    > > >> >> > }
    > > >> >> > }
    > > >> >> >
    > > >> >> > I'd like to add (in another file):
    > > >> >> > public partial class Admin_Customer
    > > >> >> > {
    > > >> >> > protected void Data_List()
    > > >> >> > { . . code . . .}
    > > >> >> > }
    > > >> >> >
    > > >> >> > Each time I complie the page cannot see the Data_List() method ?
    > > >> >> > Error Message "The name Data_List does not exist in the current contact".
    > > >> >> >
    > > >> >> > I've been scouring the web all morning with no sucess, tried a few things
    > > >> >> > like putting them in the same namespace but that does not seem to help. Also
    > > >> >> > given them the same inherit statement.
    > > >> >> >
    > > >> >> > Any suggestions Please ?
    > > >> >>
    > > >> >>
    > > >> >>
    > > >>
    > > >>
    > > >>

    > >
    > >
    > >
    > >
     
    =?Utf-8?B?RmF0IEVsdmlz?=, Jun 19, 2006
    #8
  9. re:
    > Does Juan or anyone else have any ideas here ?


    >> However I cannot use the "MyProperty" property from the Page_Load event in
    >> the original code behind class - this is what I want to do.


    A solution would be to compile your helper classes (HelperClasses.cs) into an assembly and
    then it will be a snap to call your added functions from HelperClasses.dll in the /bin directory.





    Juan T. Llibre, asp.net MVP
    aspnetfaq.com : http://www.aspnetfaq.com/
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ===================================
    "Fat Elvis" <> wrote in message
    news:...
    > Does Juan or anyone else have any ideas here ?
    >
    > Thx, Lee.
    >
    >
    >
    > "Fat Elvis" wrote:
    >
    >> Juan,
    >>
    >> Works a treat.
    >>
    >> However I cannot use the "MyProperty" property from the Page_Load event in
    >> the original code behind class - this is what I want to do.
    >>
    >> The error is "The name 'MyProperty' does not exist in the current context."
    >>
    >> Same goes for methods.
    >>
    >> Lee :eek:(
    >>
    >> "Juan T. Llibre" wrote:
    >>
    >> > Try this :
    >> >
    >> > Create a new website, with a default.aspx and a default.aspx.cs.
    >> >
    >> > Leave the default.aspx and the default.aspx.cs pages as they are.
    >> > Create an App_Code directory and create a source file named "Default.cs" in it.
    >> >
    >> > Substitute the following code for the code in Default.cs :
    >> >
    >> > ----
    >> >
    >> > public partial class _Default : System.Web.UI.Page
    >> > {
    >> > public _Default()
    >> > {
    >> > int m_MyProperty;}
    >> > // This is the property block.
    >> > public int MyProperty
    >> > {
    >> > // Returns the value of m_MyProperty.
    >> > get
    >> > {
    >> > return m_MyProperty;
    >> > }
    >> > set
    >> > {
    >> > // Checks if a valid value is being
    >> > // assigned to the property.
    >> > if (value > 5)
    >> > {
    >> > //
    >> > //TO DO
    >> > //
    >> > }
    >> > else
    >> > {
    >> > m_MyProperty = value;
    >> > }
    >> > }
    >> > }
    >> >
    >> > ----
    >> >
    >> > Now, use the Class View feature in Visual Studio and highlight the _Default partial class.
    >> >
    >> > You will see the property MyProperty listed for the
    >> > _Default partial class...which inherits from System.Web.UI.Page.
    >> >
    >> > Congratulations!
    >> > You have just extended the partial class _Default from the source file "Default.cs".
    >> >
    >> > Adapt the example to any other extension you want to add to _Default,
    >> > by adding properties or methods to Default.cs in the App_Code directory.
    >> >
    >> >
    >> >
    >> > Juan T. Llibre, asp.net MVP
    >> > aspnetfaq.com : http://www.aspnetfaq.com/
    >> > asp.net faq : http://asp.net.do/faq/
    >> > foros de asp.net, en español : http://asp.net.do/foros/
    >> > ===================================
    >> > "Fat Elvis" <> wrote in message
    >> > news:...
    >> > > Yep.
    >> > >
    >> > > I tried that and it causes a different error.
    >> > >
    >> > > Lee :eek:(
    >> > >
    >> > > "Juan T. Llibre" wrote:
    >> > >
    >> > >> Are both partial classes within the same namespace ?
    >> > >>
    >> > >> i.e.,
    >> > >>
    >> > >> in one file :
    >> > >> Namespace somenamespace
    >> > >> public partial class Admin_Customer
    >> > >>
    >> > >> in PartialClasses.cs :
    >> > >> Namespace somenamespace
    >> > >> public partial class Admin_Customer
    >> > >>
    >> > >>
    >> > >>
    >> > >>
    >> > >> Juan T. Llibre, asp.net MVP
    >> > >> aspnetfaq.com : http://www.aspnetfaq.com/
    >> > >> asp.net faq : http://asp.net.do/faq/
    >> > >> foros de asp.net, en español : http://asp.net.do/foros/
    >> > >> ===================================
    >> > >> "Fat Elvis" <> wrote in message
    >> > >> news:...
    >> > >> > Juan,
    >> > >> >
    >> > >> > The "new" partial class is in the \App_Code\PartialClasses.cs file.
    >> > >> >
    >> > >> > The .aspx page (and .aspx.cs) is in the root.
    >> > >> > Any other ideas ?
    >> > >> >
    >> > >> > Thx, Lee.
    >> > >>
    >> > >>
    >> > >> > "Juan T. Llibre" wrote:
    >> > >> >
    >> > >> >> You'll need to place the source file extending the class in the App_Code directory.
    >> > >> >>
    >> > >> >> You cannot extend a partial class in a page's code-behind source
    >> > >> >> in a different page's code-behind source.
    >> > >> >>
    >> > >> >> Try it, and view the complete class with Visual Studio's Class View feature.
    >> > >> >>
    >> > >> >>
    >> > >> >>
    >> > >> >>
    >> > >> >> Juan T. Llibre, asp.net MVP
    >> > >> >> aspnetfaq.com : http://www.aspnetfaq.com/
    >> > >> >> asp.net faq : http://asp.net.do/faq/
    >> > >> >> foros de asp.net, en español : http://asp.net.do/foros/
    >> > >> >> ===================================
    >> > >> >> "Fat Elvis" <> wrote in message
    >> > >> >> news:...
    >> > >> >> > I'd like to extend some of my Asp.net pages by using Partial Classes.
    >> > >> >> >
    >> > >> >> > Example ASP.Net Page:
    >> > >> >> > public partial class Admin_Customer : System.Web.UI.Page
    >> > >> >> > {
    >> > >> >> > protected void Page_Load(object sender, EventArgs e)
    >> > >> >> > {
    >> > >> >> > Data_List();
    >> > >> >> > }
    >> > >> >> > }
    >> > >> >> >
    >> > >> >> > I'd like to add (in another file):
    >> > >> >> > public partial class Admin_Customer
    >> > >> >> > {
    >> > >> >> > protected void Data_List()
    >> > >> >> > { . . code . . .}
    >> > >> >> > }
    >> > >> >> >
    >> > >> >> > Each time I complie the page cannot see the Data_List() method ?
    >> > >> >> > Error Message "The name Data_List does not exist in the current contact".
    >> > >> >> >
    >> > >> >> > I've been scouring the web all morning with no sucess, tried a few things
    >> > >> >> > like putting them in the same namespace but that does not seem to help. Also
    >> > >> >> > given them the same inherit statement.
    >> > >> >> >
    >> > >> >> > Any suggestions Please ?
    >> > >> >>
    >> > >> >>
    >> > >> >>
    >> > >>
    >> > >>
    >> > >>
    >> >
    >> >
    >> >
    >> >
     
    Juan T. Llibre, Jun 19, 2006
    #9
  10. Juan,

    Thanks for you help again !

    I already have a helper class DLL and was hoping to go further and generate
    the matching calls for each admin page (and use the partial classes).

    Guess I'll have to do the last bit by hand.

    Thanks again for your help.

    Lee :eek:)

    "Juan T. Llibre" wrote:

    > re:
    > > Does Juan or anyone else have any ideas here ?

    >
    > >> However I cannot use the "MyProperty" property from the Page_Load event in
    > >> the original code behind class - this is what I want to do.

    >
    > A solution would be to compile your helper classes (HelperClasses.cs) into an assembly and
    > then it will be a snap to call your added functions from HelperClasses.dll in the /bin directory.
    >
    >
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > aspnetfaq.com : http://www.aspnetfaq.com/
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ===================================
    > "Fat Elvis" <> wrote in message
    > news:...
    > > Does Juan or anyone else have any ideas here ?
    > >
    > > Thx, Lee.
    > >
    > >
    > >
    > > "Fat Elvis" wrote:
    > >
    > >> Juan,
    > >>
    > >> Works a treat.
    > >>
    > >> However I cannot use the "MyProperty" property from the Page_Load event in
    > >> the original code behind class - this is what I want to do.
    > >>
    > >> The error is "The name 'MyProperty' does not exist in the current context."
    > >>
    > >> Same goes for methods.
    > >>
    > >> Lee :eek:(
    > >>
    > >> "Juan T. Llibre" wrote:
    > >>
    > >> > Try this :
    > >> >
    > >> > Create a new website, with a default.aspx and a default.aspx.cs.
    > >> >
    > >> > Leave the default.aspx and the default.aspx.cs pages as they are.
    > >> > Create an App_Code directory and create a source file named "Default.cs" in it.
    > >> >
    > >> > Substitute the following code for the code in Default.cs :
    > >> >
    > >> > ----
    > >> >
    > >> > public partial class _Default : System.Web.UI.Page
    > >> > {
    > >> > public _Default()
    > >> > {
    > >> > int m_MyProperty;}
    > >> > // This is the property block.
    > >> > public int MyProperty
    > >> > {
    > >> > // Returns the value of m_MyProperty.
    > >> > get
    > >> > {
    > >> > return m_MyProperty;
    > >> > }
    > >> > set
    > >> > {
    > >> > // Checks if a valid value is being
    > >> > // assigned to the property.
    > >> > if (value > 5)
    > >> > {
    > >> > //
    > >> > //TO DO
    > >> > //
    > >> > }
    > >> > else
    > >> > {
    > >> > m_MyProperty = value;
    > >> > }
    > >> > }
    > >> > }
    > >> >
    > >> > ----
    > >> >
    > >> > Now, use the Class View feature in Visual Studio and highlight the _Default partial class.
    > >> >
    > >> > You will see the property MyProperty listed for the
    > >> > _Default partial class...which inherits from System.Web.UI.Page.
    > >> >
    > >> > Congratulations!
    > >> > You have just extended the partial class _Default from the source file "Default.cs".
    > >> >
    > >> > Adapt the example to any other extension you want to add to _Default,
    > >> > by adding properties or methods to Default.cs in the App_Code directory.
    > >> >
    > >> >
    > >> >
    > >> > Juan T. Llibre, asp.net MVP
    > >> > aspnetfaq.com : http://www.aspnetfaq.com/
    > >> > asp.net faq : http://asp.net.do/faq/
    > >> > foros de asp.net, en español : http://asp.net.do/foros/
    > >> > ===================================
    > >> > "Fat Elvis" <> wrote in message
    > >> > news:...
    > >> > > Yep.
    > >> > >
    > >> > > I tried that and it causes a different error.
    > >> > >
    > >> > > Lee :eek:(
    > >> > >
    > >> > > "Juan T. Llibre" wrote:
    > >> > >
    > >> > >> Are both partial classes within the same namespace ?
    > >> > >>
    > >> > >> i.e.,
    > >> > >>
    > >> > >> in one file :
    > >> > >> Namespace somenamespace
    > >> > >> public partial class Admin_Customer
    > >> > >>
    > >> > >> in PartialClasses.cs :
    > >> > >> Namespace somenamespace
    > >> > >> public partial class Admin_Customer
    > >> > >>
    > >> > >>
    > >> > >>
    > >> > >>
    > >> > >> Juan T. Llibre, asp.net MVP
    > >> > >> aspnetfaq.com : http://www.aspnetfaq.com/
    > >> > >> asp.net faq : http://asp.net.do/faq/
    > >> > >> foros de asp.net, en español : http://asp.net.do/foros/
    > >> > >> ===================================
    > >> > >> "Fat Elvis" <> wrote in message
    > >> > >> news:...
    > >> > >> > Juan,
    > >> > >> >
    > >> > >> > The "new" partial class is in the \App_Code\PartialClasses.cs file.
    > >> > >> >
    > >> > >> > The .aspx page (and .aspx.cs) is in the root.
    > >> > >> > Any other ideas ?
    > >> > >> >
    > >> > >> > Thx, Lee.
    > >> > >>
    > >> > >>
    > >> > >> > "Juan T. Llibre" wrote:
    > >> > >> >
    > >> > >> >> You'll need to place the source file extending the class in the App_Code directory.
    > >> > >> >>
    > >> > >> >> You cannot extend a partial class in a page's code-behind source
    > >> > >> >> in a different page's code-behind source.
    > >> > >> >>
    > >> > >> >> Try it, and view the complete class with Visual Studio's Class View feature.
    > >> > >> >>
    > >> > >> >>
    > >> > >> >>
    > >> > >> >>
    > >> > >> >> Juan T. Llibre, asp.net MVP
    > >> > >> >> aspnetfaq.com : http://www.aspnetfaq.com/
    > >> > >> >> asp.net faq : http://asp.net.do/faq/
    > >> > >> >> foros de asp.net, en español : http://asp.net.do/foros/
    > >> > >> >> ===================================
    > >> > >> >> "Fat Elvis" <> wrote in message
    > >> > >> >> news:...
    > >> > >> >> > I'd like to extend some of my Asp.net pages by using Partial Classes.
    > >> > >> >> >
    > >> > >> >> > Example ASP.Net Page:
    > >> > >> >> > public partial class Admin_Customer : System.Web.UI.Page
    > >> > >> >> > {
    > >> > >> >> > protected void Page_Load(object sender, EventArgs e)
    > >> > >> >> > {
    > >> > >> >> > Data_List();
    > >> > >> >> > }
    > >> > >> >> > }
    > >> > >> >> >
    > >> > >> >> > I'd like to add (in another file):
    > >> > >> >> > public partial class Admin_Customer
    > >> > >> >> > {
    > >> > >> >> > protected void Data_List()
    > >> > >> >> > { . . code . . .}
    > >> > >> >> > }
    > >> > >> >> >
    > >> > >> >> > Each time I complie the page cannot see the Data_List() method ?
    > >> > >> >> > Error Message "The name Data_List does not exist in the current contact".
    > >> > >> >> >
    > >> > >> >> > I've been scouring the web all morning with no sucess, tried a few things
    > >> > >> >> > like putting them in the same namespace but that does not seem to help. Also
    > >> > >> >> > given them the same inherit statement.
    > >> > >> >> >
    > >> > >> >> > Any suggestions Please ?
    > >> > >> >>
    > >> > >> >>
    > >> > >> >>
    > >> > >>
    > >> > >>
    > >> > >>
    > >> >
    > >> >
    > >> >
    > >> >

    >
    >
    >
     
    =?Utf-8?B?RmF0IEVsdmlz?=, Jun 20, 2006
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGF0cmljaw==?=

    ASP.Net 2.0 and partial classes

    =?Utf-8?B?UGF0cmljaw==?=, Apr 25, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    2,727
    clintonG
    Apr 26, 2005
  2. Billy
    Replies:
    2
    Views:
    520
    Billy
    Feb 1, 2006
  3. Thomas Heller
    Replies:
    13
    Views:
    877
    Michele Simionato
    Feb 8, 2007
  4. J. Clifford Dyer

    Re: Partial 1.0 - Partial classes for Python

    J. Clifford Dyer, Feb 8, 2007, in forum: Python
    Replies:
    0
    Views:
    532
    J. Clifford Dyer
    Feb 8, 2007
  5. Samuel R. Neff
    Replies:
    0
    Views:
    1,080
    Samuel R. Neff
    Jan 2, 2008
Loading...

Share This Page