由发布控件启动的 Sharepoint Web 部件验证

发布于 2024-10-09 17:12:09 字数 666 浏览 5 评论 0原文

我有一个 Web 部件,它在文本框字段上使用验证 (InputFormRequiredFieldValidator) 以防止提交空字段。在编辑模式下单击“签入以共享草稿”或“发布”时,此验证已完成,并且由于我实际上并不是在尝试提交表单,而是将其签入,所以我宁愿这样没有发生。

我怎样才能实现这个目标?

另请参阅:Sharepoint Web 部件表单验证阻止更新 Web 部件settings - 这有验证代码,以及我如何解决 EditorPart 设置验证的问题。

更新:我尝试检测 EditDisplayMode 并禁用验证器,如下所示:

if (WebPartManager.DisplayMode.Equals(WebPartManager.EditDisplayMode))
{
     messageRequiredValidator.Enabled = false;
}

这不起作用 - 签入页面时我仍然收到验证失败消息。也许我没有正确检测到 DisplayMode。

I have a web part which uses validation (InputFormRequiredFieldValidator) on a textbox field to prevent submission of an empty field. When clicking on Check In to Share Draft or Publish while in Edit mode, this validation is done, and since I am not actually trying to submit the form, but rather check it in, I'd rather this didn't happen.

How can I achieve this?

See also: Sharepoint web part form validation blocks updating web part settings - this has the validation code, and how I solved the problem of the EditorPart setting off the validation.

Update: I've tried detecting EditDisplayMode and disabling the validator as follows:

if (WebPartManager.DisplayMode.Equals(WebPartManager.EditDisplayMode))
{
     messageRequiredValidator.Enabled = false;
}

This doesn't work - I still get the validation failure message when Checking in the page. Maybe I am not detecting the DisplayMode correctly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

阿楠 2024-10-16 17:12:09

正如 Madhur 指出的那样,我需要检查 BrowseDisplayMode。我开始在编辑模式下关闭验证器并依赖默认值 true,但还有其他显示模式,例如设计,我也可能会遇到问题。所以我检查了 BrowseDisplayMode,如下所示:

WebPartManager mgr = WebPartManager.GetCurrentWebPartManager(Page);
if (mgr.DisplayMode.Equals(mgr.SupportedDisplayModes["Browse"]))
{
     messageRequiredValidator.Enabled = true;
}
else
{
     messageRequiredValidator.Enabled = false;
}

这似乎可以解决问题。如果有人对此方法有任何反馈,我们将不胜感激。

As Madhur pointed out I needed to check for BrowseDisplayMode. I started to go down the route of switching off the validator when in Edit mode and relying on the default of true, but there are other display modes such as Design, where I might also get the problem. So I checked for BrowseDisplayMode as follows:

WebPartManager mgr = WebPartManager.GetCurrentWebPartManager(Page);
if (mgr.DisplayMode.Equals(mgr.SupportedDisplayModes["Browse"]))
{
     messageRequiredValidator.Enabled = true;
}
else
{
     messageRequiredValidator.Enabled = false;
}

This seems to do the trick. Would appreciate any feedback anyone has on this method.

夜空下最亮的亮点 2024-10-16 17:12:09

为了让它发挥作用,我经历了一个痛苦的世界,所以我想分享一下。

尽管我正确地获取了显示模式,但无论模式如何,我的控件都会继续验证。

最终的解决方案涉及三件事:

  1. 默认情况下禁用 RegularExpressionValidator - 即启用 - “false”
  2. 将我的代码移动到 CreateChildControls 方法中。
  3. 添加 ELSE 子句!没有它,验证总是设置为 true。别问我为什么。

这是代码。先前提供的示例的基本变化。

// 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 = "<strong>" + mode + " mode</strong>: Validation is disabled.";
}

I went through a world of pain getting this to work so thought I'd share.

Even though I was correctly getting the display mode, my control continued to validate regardless of the mode.

The final solution involved three things:

  1. Disabling the RegularExpressionValidator by default - i.e. Enabled-"false"
  2. Moving my code into the CreateChildControls method.
  3. Adding an ELSE clause! Without it, validation was ALWAYS set to true. Don't ask me why.

And here's the code. Basic variation on previously supplied examples.

// 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 = "<strong>" + mode + " mode</strong>: Validation is disabled.";
}
谷夏 2024-10-16 17:12:09

使用 WebPartManager.DisplayMode 枚举检测当前页面模式并仅在 BrowseDisplayMode 中启用验证。

这就是 SharePoint OOTB Web 部件执行验证的方式。

http://msdn.microsoft .com/en-us/library/system.web.ui.webcontrols.webparts.webpartmanager.displaymode.aspx

Use the WebPartManager.DisplayMode enumeration to detect the current page mode and enable the validation only in BrowseDisplayMode

That's how the SharePoint OOTB webparts does validation.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webpartmanager.displaymode.aspx

_失温 2024-10-16 17:12:09
//disable javascript on sharepoint edit mode
$(function () {
    var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;

    if (inDesignMode == "1") {
        // page is in edit mode
        if ((typeof (Page_Validators) != "undefined") && (Page_Validators != null)) {
            var i;
            for (i = 0; i < Page_Validators.length; i++) {
                ValidatorEnable(Page_Validators[i], false);
            }
        }
    }
    else {
        // page is in browse mode
    } 
});
//disable javascript on sharepoint edit mode
$(function () {
    var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;

    if (inDesignMode == "1") {
        // page is in edit mode
        if ((typeof (Page_Validators) != "undefined") && (Page_Validators != null)) {
            var i;
            for (i = 0; i < Page_Validators.length; i++) {
                ValidatorEnable(Page_Validators[i], false);
            }
        }
    }
    else {
        // page is in browse mode
    } 
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文