Thanks Ishai. This also does the trick. Is one preferred over the other?

if (SPContext.Current.FormContext.FormMode == SPControlMode.Display)
{
    // Do something
}
else
{
    // Do the other thing
}

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Paul Noone
Sent: Tuesday, 24 January 2012 12:28 PM
To: ozMOSS
Subject: RE: Prevent WP field Validation in Edit Mode

Thanks Ishai.
I was getting the correct mode. The final solution involved disabling the 
RegularExpressionValidator by default - and adding an ELSE clause!
Without it, validation was ALWAYS set to true. Don't ask me why!!
    // Get the current display mode of the WPM
    WebPartManager wp = WebPartManager.GetCurrentWebPartManager(Page);
    String mode = wp.DisplayMode.Name;
    // Enable validation in BrowseDisplayMode only
    if (wp.DisplayMode == WebPartManager.BrowseDisplayMode)
    {
        reqJournal.Enabled = true;
    }
    else
    {
        reqJournal.Enabled = false;
        lblMsg.Text = "<span style=\"color:red\"><strong>" + mode + " 
mode</strong>: Validation is disabled.</span>";
    }
From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Ishai Sagi
Sent: Tuesday, 24 January 2012 12:17 PM
To: ozMOSS
Subject: RE: Prevent WP field Validation in Edit Mode

Try to check the form mode, not the display mode.
SPContext.Current.Form.Mode or something like it is what you should be 
checking. No need for web part manager.



[cid:image002.jpg@01CCDA96.3C18CE70]Ishai Sagi | Solutions Architect
0488 789 786 | is...@exd.com.au<mailto:is...@exd.com.au> | 
www.sharepoint-tips.com<http://www.sharepoint-tips.com/> | 
@ishaisagi<http://twitter.com/ishaisagi>

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Paul Noone
Sent: Tuesday, 24 January 2012 11:48 AM
To: ozMOSS
Subject: RE: Prevent WP field Validation in Edit Mode

I've disabled my RegularExpressionValidator by default and am now only enabling 
it if the page is in BrowseDisplayMode. I've also moved the code into the 
CreateChildControls method as some people have suggested but validation still 
occurs in ANY mode! If I comment out line 8 then it never occurs (obviously!).

What am I doing wrong??

        <asp:RegularExpressionValidator runat="server" ... Enabled="false"/>

1        protected override void CreateChildControls()
2        {
3            // Get the current display mode of the WPM
4            WebPartManager wp = WebPartManager.GetCurrentWebPartManager(Page);
5            // Enable validation in BrowseDisplayMode only
6            if (wp.DisplayMode == WebPartManager.BrowseDisplayMode)
7            {
8                reqJournal.Enabled = true;
9            }
10        }

From: ozmoss-boun...@ozmoss.com<mailto:ozmoss-boun...@ozmoss.com> 
[mailto:ozmoss-boun...@ozmoss.com]<mailto:[mailto:ozmoss-boun...@ozmoss.com]> 
On Behalf Of Paul Noone
Sent: Tuesday, 24 January 2012 9:49 AM
To: ozMOSS (ozmoss@ozmoss.com<mailto:ozmoss@ozmoss.com>)
Subject: Prevent WP field Validation in Edit Mode

Hi all,
I know we've been down this road before but I'm continuing to have issues with 
web part fields being validated when a user tries to check-in/save/publish a 
page that it appears on.
I know that the display mode is being correctly determined because the 
CauseValidation attribute is being added to the field. However it's not 
preventing validation from occurring.
Maybe setting the validator's ControlToValidate valuer to "" would be more 
reliable??
        protected void Page_Load(object Sender, EventArgs e)
        {
            // Get the current display mode of the WPM
            WebPartManager wp = 
WebPartManager.GetCurrentWebPartManager(this.Page);
            if (!Page.IsPostBack)
            {
                // Disable validation in Edit or Design Mode
                if (wp.DisplayMode == WebPartManager.EditDisplayMode || 
wp.DisplayMode == WebPartManager.DesignDisplayMode)
                {
                    // In Edit or Design Mode
                    txtJournal.Attributes.Add("CausesValidation", "false");
                }
            }
        }
Kind regards,

Paul Noone

---------------------------------------------------
Online Developer/SharePoint Administrator
Infrastructure Team, ICT
Catholic Education Office, Sydney
p: (02) 9568 8461
f: (02) 9568 8483
e: paul.no...@ceosyd.catholic.edu.au<mailto:paul.no...@ceosyd.catholic.edu.au>
w: http://www.ceosyd.catholic.edu.au/

<<inline: image001.jpg>>

<<inline: image002.jpg>>

_______________________________________________
ozmoss mailing list
ozmoss@ozmoss.com
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss

Reply via email to