Is my SharePoint web page in Edit Mode????

Hi all,

Recently I developed a custom web part, to get some user feedback. The web part contain some validators (required field validators) and some of my custom web part properties (A property to get a SharePoint list URL). After completing the web part I embed it on a page. While testing the web part, i noticed when I go edit web part properties, and try to save my changes by pressing OK, or Apply button, it trigged all my validators.

So as a solution I had to disable validators in in my web part, ONLY when web part is in EDIT mode. To identify the current page is in edit mode I used the following code.

if(SPContext.Current.FormContext.FormMode == SPControlMode.Edit){
// Disable my validators here.

The SPControlMode enumeration has four possible choices.

1) Display

2) Edit

3) Invalid

4) New

So when ever you come across a such requirement, you can use above code snippet.  :)

Leave a Reply

Your email address will not be published. Required fields are marked *