473,729 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extending ASP.net pages using Partial Classes

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.P age
{
protected void Page_Load(objec t 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
9 5785
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******@discu ssions.microsof t.com> wrote in message
news:3C******** *************** ***********@mic rosoft.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.P age
{
protected void Page_Load(objec t 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
Juan,

The "new" partial class is in the \App_Code\Parti alClasses.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******@discu ssions.microsof t.com> wrote in message
news:3C******** *************** ***********@mic rosoft.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.P age
{
protected void Page_Load(objec t 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
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******@discu ssions.microsof t.com> wrote in message
news:21******** *************** ***********@mic rosoft.com...
Juan,

The "new" partial class is in the \App_Code\Parti alClasses.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******@discu ssions.microsof t.com> wrote in message
news:3C******** *************** ***********@mic rosoft.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.P age
> {
> protected void Page_Load(objec t 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
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******@discu ssions.microsof t.com> wrote in message
news:21******** *************** ***********@mic rosoft.com...
Juan,

The "new" partial class is in the \App_Code\Parti alClasses.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******@discu ssions.microsof t.com> wrote in message
news:3C******** *************** ***********@mic rosoft.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.P age
> {
> protected void Page_Load(objec t 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
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.P age
{
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.P age.

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******@discu ssions.microsof t.com> wrote in message
news:C5******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.com> wrote in message
news:21******** *************** ***********@mic rosoft.com...
> Juan,
>
> The "new" partial class is in the \App_Code\Parti alClasses.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******@discu ssions.microsof t.com> wrote in message
>> news:3C******** *************** ***********@mic rosoft.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.P age
>> > {
>> > protected void Page_Load(objec t 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
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.P age
{
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.P age.

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******@discu ssions.microsof t.com> wrote in message
news:C5******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.com> wrote in message
news:21******** *************** ***********@mic rosoft.com...
> Juan,
>
> The "new" partial class is in the \App_Code\Parti alClasses.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******@discu ssions.microsof t.com> wrote in message
>> news:3C******** *************** ***********@mic rosoft.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.P age
>> > {
>> > protected void Page_Load(objec t 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
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.P age
{
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.P age.

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******@discu ssions.microsof t.com> wrote in message
news:C5******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.com> wrote in message
> news:21******** *************** ***********@mic rosoft.com...
> > Juan,
> >
> > The "new" partial class is in the \App_Code\Parti alClasses.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******@discu ssions.microsof t.com> wrote in message
> >> news:3C******** *************** ***********@mic rosoft.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.P age
> >> > {
> >> > protected void Page_Load(objec t 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
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.d ll 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******@discu ssions.microsof t.com> wrote in message
news:44******** *************** ***********@mic rosoft.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.P age
> {
> 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.P age.
>
> 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******@discu ssions.microsof t.com> wrote in message
> news:C5******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.com> wrote in message
> >> news:21******** *************** ***********@mic rosoft.com...
> >> > Juan,
> >> >
> >> > The "new" partial class is in the \App_Code\Parti alClasses.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******@discu ssions.microsof t.com> wrote in message
> >> >> news:3C******** *************** ***********@mic rosoft.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.P age
> >> >> > {
> >> >> > protected void Page_Load(objec t 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
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.d ll 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******@discu ssions.microsof t.com> wrote in message
news:44******** *************** ***********@mic rosoft.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.P age
> {
> 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.P age.
>
> 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******@discu ssions.microsof t.com> wrote in message
> news:C5******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.com> wrote in message
> >> news:21******** *************** ***********@mic rosoft.com...
> >> > Juan,
> >> >
> >> > The "new" partial class is in the \App_Code\Parti alClasses.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******@discu ssions.microsof t.com> wrote in message
> >> >> news:3C******** *************** ***********@mic rosoft.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.P age
> >> >> > {
> >> >> > protected void Page_Load(objec t 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2588
by: clintonG | last post by:
Are developers still using namespaces in their code for pages or is this practice no longer neccessary for pages? I don't see the rationale here. except perhaps for controls that are comprised of compiled assemblies with methods and properties that may cause conflicts with other classes. What is your current practice for 2.0 development when using VS2005? <%= Clinton Gallagher
8
1956
by: Anthony Williams | last post by:
Morning all, I'm having a wee problem with a project I'm working on at the moment. I'm leading my company into producing a website, based upon Web Standards, which will be created using XHTML and CSS, and powered by ASP.NET. My first problem, which I'm near to solving, was that ASP.NET doesn't produce valid XHTML output. We don't want to spend money on third-party components, and we can't wait for ASP.NET 2.0, so we needed to find a
10
2241
by: Christophe Peillet | last post by:
I am trying to create a BasePage for use in a large asp.net application, that will centrally provide certain extra properties and logic to the application. (The web project makes use Master Pages as well.) I want to make a property named TitleResourceKey, for example, that contains the resource key used to translate the page title and, using reflection and the CustomLocalisationKey attribute that points to the property this key...
0
1038
by: twistedinferno | last post by:
I have upgraded an application from asp.net 1.1 to asp.net 2 (VS 2005). The problem with this is I had a number of declared controls in base pages. In the base pages I use the events of the controls and also override functions that interact with these controls. It sounds a little complicated but works very well. My problem is I can't seem to do this in asp.net 2 because it uses partial classes for the control declaration and won't let...
3
1975
by: Aryan | last post by:
Hi, I have problem in creating Partial Class for ASPX pages. As my Codebase file for ASPX page is having more then 2500 lines of code. So its very hard to maintain the code. So I wanted to know, how can I create partial classes to handle this situation OR if I create new class files in App_Code folder to handle major code of ASPX code behind page then how can I get the access to the various Web Control which I have created on the ASPX...
6
3990
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public string UID; public string PWD; }
4
1064
by: =?Utf-8?B?QWxleA==?= | last post by:
I upgraded a web application into a VS 2005/.NET 2.0 Web Application Project (as opposed to a Website project), but did not set the pages to be partial classes. Looking at the code behind, you can see the declarations of all the controls as it was in Visual Studio 2003. But when I add a new control, VS doesn't add the new declare in the code behind, and before you can reference the control, you manually have to add the declaration in the...
1
1739
by: =?Utf-8?B?Q2Fsdmlu?= | last post by:
Dear all, I had used partial class to extend typed dataset(ex. add a method to TypedDataTable) in my windows-base applications and it works well. But when I try it in a web services project, those extend functions which is visible within web project, but invisible to client.(I create a windows-base application then add web references point to that web project, client application will not be able to use extend function, properties etc.) ...
0
3537
by: Samuel R. Neff | last post by:
We're migrating our .NET 1.1 web application to .NET 3.5 and during conversion we clicked "Convert to Web Application" on the web project. The results from this conversion were inconsistent. 1. Many pages were not converted at all. They're still aspx and cs files with generated code inside the cs file and still no partial class implementation. 2. Designer classes empty. A few pages were converted to partial classes, but the...
0
9428
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9288
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9154
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph DuprÚ who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4797
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3240
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.