Tuesday, March 13, 2012

Troubles reference this pointer in external class file

I'm wanting to reference page controls from a cs file in the app_code
directory. I'm getting a _Defaullt could not be found, missing
directive or assembly reference error. Very simple example below.
Default.aspx.cs:
using System;
using System.Web.UI;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Class1.UpdateButtonText(this);
}
}
Class1.cs
using System;
public class Class1
{
public Class1()
{
}
public static void UpdateButtonText(_Default global_Default)
{
}
}
Peter Kellner
http://peterkellner.netThis is impossible as the App_Code directory is compiled prior to your aspx
files.
-Brock
http://staff.develop.com/ballen

> I'm wanting to reference page controls from a cs file in the app_code
> directory. I'm getting a _Defaullt could not be found, missing
> directive or assembly reference error. Very simple example below.
> Default.aspx.cs:
> using System;
> using System.Web.UI;
> public partial class _Default : Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> }
> protected void Button1_Click(object sender, EventArgs e)
> {
> Class1.UpdateButtonText(this);
> }
> }
> --
> Class1.cs
> using System;
> public class Class1
> {
> public Class1()
> {
> }
> public static void UpdateButtonText(_Default global_Default)
> {
> }
> }
> Peter Kellner
> http://peterkellner.net
On Fri, 9 Jun 2006 23:24:03 +0000 (UTC), Brock Allen
<ballen@.NOSPAMdevelop.com> wrote:

>This is impossible as the App_Code directory is compiled prior to your aspx
>files.
>-Brock
>http://staff.develop.com/ballen
>
Thanks,
Makes sense to me now. When I moved Class2 directly into the aspx.cs
file it of course worked. Hadn't really thought about the order of
compilation.
-peter
----
using System;
using System.Web.UI;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Class2.UpdateButtonText(this);
}
}
public class Class2
{
public Class2()
{
}
public static void UpdateButtonText(_Default global_Default)
{
throw new Exception("The method or operation is not
implemented.");
}
}
Peter Kellner
http://peterkellner.net

0 comments:

Post a Comment