By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,686 Members | 2,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,686 IT Pros & Developers. It's quick & easy.

Extending ASP.net pages using Partial Classes

P: n/a
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 ?
Jun 15 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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" <Fa******@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
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 ?

Jun 15 '06 #2

P: n/a
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" <Fa******@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
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 ?


Jun 15 '06 #3

P: n/a
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" <Fa******@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
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" <Fa******@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
> 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 ?


Jun 15 '06 #4

P: n/a
Yep.

I tried that and it causes a different error.

Lee :o(

"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" <Fa******@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
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" <Fa******@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
> 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 ?


Jun 15 '06 #5

P: n/a
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" <Fa******@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.com...
Yep.

I tried that and it causes a different error.

Lee :o(

"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" <Fa******@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
> 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" <Fa******@discussions.microsoft.com> wrote in message
>> news:3C**********************************@microsof t.com...
>> > 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 ?
>>
>>
>>



Jun 15 '06 #6

P: n/a
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 :o(

"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" <Fa******@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.com...
Yep.

I tried that and it causes a different error.

Lee :o(

"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" <Fa******@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
> 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" <Fa******@discussions.microsoft.com> wrote in message
>> news:3C**********************************@microsof t.com...
>> > 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 ?
>>
>>
>>


Jun 16 '06 #7

P: n/a
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 :o(

"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" <Fa******@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.com...
Yep.

I tried that and it causes a different error.

Lee :o(

"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" <Fa******@discussions.microsoft.com> wrote in message
> news:21**********************************@microsof t.com...
> > 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" <Fa******@discussions.microsoft.com> wrote in message
> >> news:3C**********************************@microsof t.com...
> >> > 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 ?
> >>
> >>
> >>
>
>
>


Jun 19 '06 #8

P: n/a
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" <Fa******@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com... 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 :o(

"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" <Fa******@discussions.microsoft.com> wrote in message
> news:C5**********************************@microsof t.com...
> > Yep.
> >
> > I tried that and it causes a different error.
> >
> > Lee :o(
> >
> > "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" <Fa******@discussions.microsoft.com> wrote in message
> >> news:21**********************************@microsof t.com...
> >> > 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" <Fa******@discussions.microsoft.com> wrote in message
> >> >> news:3C**********************************@microsof t.com...
> >> >> > 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 ?
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
>

Jun 19 '06 #9

P: n/a
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 :o)

"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" <Fa******@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
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 :o(

"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" <Fa******@discussions.microsoft.com> wrote in message
> news:C5**********************************@microsof t.com...
> > Yep.
> >
> > I tried that and it causes a different error.
> >
> > Lee :o(
> >
> > "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" <Fa******@discussions.microsoft.com> wrote in message
> >> news:21**********************************@microsof t.com...
> >> > 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" <Fa******@discussions.microsoft.com> wrote in message
> >> >> news:3C**********************************@microsof t.com...
> >> >> > 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 ?
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
>


Jun 20 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.