I came across a post by Rui Melo at http://mystepstones.wordpress.com/ regarding detecting whether a form is in New, Edit or Display mode and it reminded me of something else;
When building custom NewForm, EditForm and DispForm’s in SharePoint you may have code such as validators firing when you dont want to, for instance when the page is in “Edit Page Mode”. This can become annoying as when you go to click either Ok or Apply the validation kicks in;

However you can use SPWebPartManager DisplayMode to ensure that your code only runs when you want it to, such as for the dummy validator below;
protected void Validate_Proposed(object source, ServerValidateEventArgs args)
{
if (SPWebPartManager.GetCurrentWebPartManager(this.Page).DisplayMode.Name.Equals("Browse"))
{
if (ValidTest == True)
{
args.IsValid = true; \\ ie: your custom test passed
}
else
{
((CustomValidator) source).ErrorMessage = "You did something invalid.";
args.IsValid = false; \\ ie: your custom test failed
}
}
}
With the code above the validator will only run if the Page is in browse mode, it will not kick in if the page is in Edit Page Mode – handy.
From what I can tell there are 9 modes for SPWebPartManager.GetCurrentWebPartManager(this.Page).DisplayMode.Name;
Browse, Edit, Catalog, Design, ExtensibleView, GallerySearch, Import, Navigation and ToolPaneError.
pradeep kumar
what is ValidTest over here. can u explain more on this???
pradeep kumar
can u explain indepth detail on this??
aaron
Sorry Pradeep there was a little psuedo code in there.
if (ValidTest == True) was just to demonstrated the if you confirmed that the page was not in EditMode, you could run you own test, if it passed you could continue, if it failed then you could set the error message.
ValidTest is just a way of writing “your code here…”. I changed the example a bit to make this clearer.