Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
 SPControlMode Enumeration

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
SPControlMode Enumeration (Microsoft.SharePoint.WebControls)

Namespace: Microsoft.SharePoint.WebControls
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
Public Enumeration SPControlMode
Visual Basic (Usage)
Dim instance As SPControlMode
C#
public enum SPControlMode
  Member name Description
Display  
Edit  
Invalid  
New  
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Why no description?      shangmeizhai   |   Edit   |   Show History
i want to know it!
Tags What's this?: Add a tag
Flag as ContentBug
SharePoint Page Design Mode      kuke   |   Edit   |   Show History

This enum is used by SPFormContext.FormMode: http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spformcontext.formmode.aspx.

It's roughly equivalent to Microsoft.ContentManagement.WebControls.WebAuthorContext in MCMS and a reasonable replacement for the obsolete WebPart.BrowserDesignMode in SPS2003. (As the ASP.NET 2.0 WebPartManager in MOSS is null).

SPControlMode      Content Master Ltd   |   Edit   |   Show History

Description

The SPControlMode enumeration enables you to test or set the mode for controls on a form. The SPControlMode enumeration contains four possible values, Display, Edit, New, and Invalid. If the FormMode of a form is SPControlMode.Display, controls on the form will be read only. If the FormMode of a form is SPControlMode.Edit, controls on the form will be editable. If the FormMode of a form is SPControlMode.New, the form will be blank to enable a user to add a new item. Finally the FormMode of a form could be SPControlMode.Invalid. ControlMode.Invalid is the default value for a form FormMode, and indicates that the FormMode has not been set.

Usage Scenarios

You would typically use the SPControlMode enumeration to perform conditional logic in your code, for example to change the way that a control is rendered on a Web Part based on the state of the form. You would also use the SPControlMode enumeration to change the state of a form; for example, as part of a button event handler.

The following code samples show how to test the current mode of the form and display a message accordingly in the Render method of a Web Part. The samples also show how to change the current mode of a form in a custom SetFormMode method.

C# Code Sample

protected override void Render(HtmlTextWriter writer)
{
if (SPContext.Current.FormContext.FormMode == SPControlMode.Display)
{
writer.Write("SPControlMode: Display");
}
if (SPContext.Current.FormContext.FormMode == SPControlMode.Edit)
{
writer.Write("SPControlMode: Edit");
}
if (SPContext.Current.FormContext.FormMode == SPControlMode.New)
{
writer.Write("SPControlMode: New");
}
if (SPContext.Current.FormContext.FormMode == SPControlMode.Invalid)
{
writer.Write("SPControlMode: Invalid");
}
}
private void SetFormMode(SPControlMode mode)
{
SPContext.Current.FormContext.SetFormMode(mode, true);
}

Visual Basic .NET Code Sample

Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter)
If SPContext.Current.FormContext.FormMode = SPControlMode.Display Then
writer.Write("SPControlMode: Display")
End If
If SPContext.Current.FormContext.FormMode = SPControlMode.Edit Then
writer.Write("SPControlMode: Edit")
End If
If SPContext.Current.FormContext.FormMode = SPControlMode.[New] Then
writer.Write("SPControlMode: New")
End If
If SPContext.Current.FormContext.FormMode = SPControlMode.Invalid Then
writer.Write("SPControlMode: Invalid")
End If
End Sub
Private Sub SetFormMode(ByVal mode As SPControlMode)
SPContext.Current.FormContext.SetFormMode(mode, True)
End Sub
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker