Unique Static Variable

Hi All,

I have a C# Web Part I am developing in VS2010. 

I have a drop down list in it that is configured as public/private (tried both) static.  This gives it retention across page refreshes, but when another Users accesses and changes the drop down list value (or the same User from another tab/window) the value changes to the last one selected.

Is there any way to correct this without losing the variable persistence functionality?

Thanks,

MK

January 23rd, 2014 4:53pm

You should not use static variables as a way to get persistency. You might want to consider other possibilities such as:

1) Storing the variable somewhere in SharePoint, for example, in a list

2) Storing the variable in the cache  

3) Leverage the AppFabric to store the variable

Free Windows Admin Tool Kit Click here and download it now
January 23rd, 2014 5:19pm

Alain,

Thanks for the reply!

I think only the first option would work in my scenario.  I have been thinking of implementing a hidden label that stores the current date-time and writing that along with the SPUser.LoginName and the drop down lists current value and then pulling that data back into the drop down list, but then I'd have to figure out a way to create persistence on the label for comparison after the post-back.  Maybe I could just skip the label, write the datetime to the list, and find the datetime value in the list closest to to the current datetime?  I'm still thinking this through . . .

Thanks,

MK

January 23rd, 2014 8:16pm

If your goal is to retain variables after a postback, you don't need to store the variable in SharePoint. You can use the Page Viewstate. 

I would suggest learning about: ASP.net Page Life Cycle and the ViewState

Free Windows Admin Tool Kit Click here and download it now
January 24th, 2014 6:55am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics