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.  🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s