DEH
DEH

Reputation: 1747

Casting to specific asp.net page type

I have an asp.net page with a code-behind class definition as follows:

public partial class examplepage : System.Web.UI.Page

I'd like to set a public property within the page that I can reference from other classes. My understanding is that if I cast to examplepage then I should be able to get at the public property that is specific to example page, as in:

string test=((examplepage)HttpContext.Current.Handler).propertyX;

However, when I try casting as above the compiler does not recognise examplepage. Can anyone tell me how I can cast? I have no specific namespaces defined.

Thanks

Upvotes: 1

Views: 1829

Answers (3)

DEH
DEH

Reputation: 1747

In case anyone's interested the following is what I switched to:

public partial class examplepage : System.Web.UI.Page, ISomeStuff

and

string test = ((ISomeStuff)HttpContext.Current.Handler).propertyX; 

Thanks for the advice folks

Upvotes: 2

DEH
DEH

Reputation: 1747

I've just read that ASP.NET 2.0 does not support casting on partial classes because at compile time the class "does not exist".

Assuming this to be true, I'd like to remove the "partial" keyword from the class definition. The compiler won't let me do this though, stating that another partial definition exists elsewhere. Is this the designer? Anyone know how I can avoid partial classes so I can cast as I want to?

Upvotes: 0

Guffa
Guffa

Reputation: 700152

If your class is in a different namespace, you have to specify the namespace for your web pages:

string test = ((MyWebApp.examplepage)HttpContext.Current.Handler).propertyX;

Upvotes: 0

Related Questions