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'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:

  [WebBrowsable(true),
   Category("AD Configuration"),
   Personalizable(PersonalizationScope.Shared),
   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 is this the right way to do it and why doesn't it resfresh automatically.

Ami i missing on the pre render or something?

share|improve this question
add comment

2 Answers

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.

share|improve this answer
    
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 '11 at 7:08
add comment

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.

share|improve this answer
add comment

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.