Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am developing a Visual Web Part. I have attributes the Visual Web Part consumes. When i use these, I have to re-set the value everytime I re-deploy the web part (by hitting F5).

Here is an example:

    public static bool ShowCaseType= true;
    [FriendlyNameAttribute("Show Case Time When Multiple (Recomended)"),
    Category("My Configuration"),
    DefaultValue(true),
    WebPartStorage(Storage.Shared),
    Personalizable(PersonalizationScope.Shared),
    WebBrowsable(true)]
    public bool _ShowCaseType
    {
        get
        {
            return ShowCaseType;
        }
        set
        {
            ShowCaseType= value;
        }
    }

If i set the above to unchecked in the web part, I stop the application and start it once again, and it has been reset.

share|improve this question

migrated from stackoverflow.com Feb 20 '12 at 22:09

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 2 down vote accepted

First, I think you should change declaration of first line to following. There is no reason to keep it public static

private bool ShowCaseType= true; 
share|improve this answer
    
I thought this had something to do with it, but then how do i get the value from this if it is not static? I need my visualwebpart (control) to be able to access it. –  Bill Daugherty Feb 21 '12 at 4:55
1  
Thanks, this helped... i figured out my last question: social.technet.microsoft.com/Forums/en-US/… –  Bill Daugherty Feb 21 '12 at 5:36

Agree with Ashish. this is why it needs to be changed every time. Making the variable static makes it bound to the type, not the instance. So it's set 1 time, but on redeploy / iisreset will revert to it's original value. By reloading the appdomain (resetting IIS) it looses it's (in memory) value.

share|improve this answer
    
I thought this had something to do with it, but then how do i get the value from this if it is not static? I need my visualwebpart (control) to be able to access it. –  Bill Daugherty Feb 21 '12 at 4:54
    
Thanks, this helped... i figured out my last question: social.technet.microsoft.com/Forums/en-US/… –  Bill Daugherty Feb 21 '12 at 5:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.