Setting a web part variable that maintains it’s value even after the browser is closed.

Don't know if you'll find this useful, but I did... especially when you're doing something that you don't want to do again everytime the web part loads. For example, when you want all the users in a drop down list, but don't want to keep querying the entire user list each time the web part opens.

This will definitely help with performance since the entire user list is in a single variable that can be queried across all sharepoint users after it loads just once by any single user.

The code below is for the entire class. I posted the whole thing because it was nice and short

using System;
using System.Collections.Generic;
using System.Text;

namespace UserList
{
public class GlobalVariable
{
public static string AllUsers;
public static DateTime ExpirationTime;
}
}

I placed a global expiration time above so I can check when to actually refresh the global variables list. I usually set it to expire at midnight, so the first person in the next day will be the one to populate this variable with all the users (for everyone's use) again.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.