Search code examples
c#web-parts

Sharepoint property updating over multiple pages


I have a webpart that have a property names FacilityID. The webpart should display facility information on the facility page, but now it seems like the properties are syncing between the different pages.

So here is one example of a property:

FILE: RSFacilityHeader.cs
     public int FacilityID = 0;
        [Category("Facility Settings"),
        Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Override Facility ID"),
        WebDescription("Facility ID will be automatically picked up from the page's setting. Here you can override if you want.")]
        public int _FacilityID
        {
            get{return FacilityID; } set {FacilityID = value;}
        } // End of facility id.

To get the property we use this code:

FILE: RSFacilityHeaderUserControl.ascx.cs
int id = RSFacilityHeader.FacilityID;

I only want the value to be on the current instance not on all the webparts. Anyone know why its like this?

Thanks for any input.


Solution

  • Yea, this was not the best place Kyle, but did not know about the sharepoint page..

    But to answer my own question so if other people search for it.

    If you change a webpart property from static to just internal you can use the following code to get the value:

    FILE: RSRacilityHeaderUserControl.ascx.cs
    RSFacilityHeader parent = (RSFacilityHeader)this.Parent;
    

    It works perfectly! :-)..

    Thanks