I'm working on a visual webpart and I need to create a custom property text field.This will be used to set how many days password would expire. See below:

   Category("AD Configuration"),
   WebDisplayName("Enter days for Passwords to Expiry"),
   WebDescription("AD Password Expiry")]
  public Int32 LdapProp
        get { return expvalue; }
        set { expvalue = value; }

public static Int32 expvalue;

and then set it like this:

DateTime expDate = DateTime.FromFileTime(LngString).AddDays(VisualWebPart1.expvalue);

When i edit the webpart the default is set to 0.
Then when i set it to e.g 25 and click apply it doesn't work first then when i refresh the page it works.
Just wondering if this is the right way to do it and why doesn't it refresh automatically.

Am I missing on the pre-render or something?

2 Answers 2


I agree with Jorge, what you are seeing is typically what happens to me. When you hit apply, the webpart's HTML is rendered before the event fires that applies the value to the webpart properties. So another page load is needed to see the new property value reflected in the webpart's output.

You might need to do a little more if you want to restrict access to only admin can change the value. My initial thought is to create an application page (_layouts) that allows you to configure the values for the site, site collection, or web application (depending on your needs) and then store the value in the property bag of that object. Then your webpart can read from the same property bag.


You're not missing anything. It is indeed how it works. If you click Apply, and then click OK, on the seconbd postback the page will be refreshed with the new value.

  • Thanks Jorge.But the other thing is i don't want users to be able to modify this value but only for administrators.When they first login the value isn't set so the status isn't correct.So what i want is Admin would be able to set it for all users.Any ideas
    – naijacoder
    Sep 26, 2011 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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