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
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
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;
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?
精彩评论