In my SharePoint 2010 c# / asp.net site, I have a class defined like
namespace PDF_Library.VisualWebPart1
{
public partial class PDF_Library : Usercontrol
{
public static PDF_Library current;
protected void Page_Load(object sender, EventArgs e)
{
current = (PDF_Library)this;
}
}
}
public static class Page_State
{
public static Page is_display()
{
return PDF_Library.current.Page; // didn't work...
}
}
It doesn’t have a constructor.
How can I get the reference to the current instance of this class?
I tried something like this in the top
public static PDF_Library current;
Then in a function it had
current = (PDF_Library)this;
But that didn’t work…
You need to understand that it does not work this way. Your question is tagged with asp.net – multi-user, multi-threaded environment where multiple instances of
PDF_Libraryuser control will be created all the time. It is absolutely uncertain which one of them will be hanging offPDF_Library.current. You need to rethink your design.More on this:
Pageinstance is disposed of when the request processing is finished. Normally this instance with all its controls and things such asResponse,Request,Contextetc will be set for garbage collection. Because you keep a reference to aUserControlinstance in a static field, all these objects (includingPage) will be kept in memory until thiscurrentreference is replaced with something else.