由发布控件启动的 Sharepoint Web 部件验证
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如 Madhur 指出的那样,我需要检查 BrowseDisplayMode。我开始在编辑模式下关闭验证器并依赖默认值 true,但还有其他显示模式,例如设计,我也可能会遇到问题。所以我检查了 BrowseDisplayMode,如下所示:
这似乎可以解决问题。如果有人对此方法有任何反馈,我们将不胜感激。
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:
This seems to do the trick. Would appreciate any feedback anyone has on this method.
为了让它发挥作用,我经历了一个痛苦的世界,所以我想分享一下。
尽管我正确地获取了显示模式,但无论模式如何,我的控件都会继续验证。
最终的解决方案涉及三件事:
这是代码。先前提供的示例的基本变化。
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:
And here's the code. Basic variation on previously supplied examples.
使用
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 inBrowseDisplayMode
That's how the SharePoint OOTB webparts does validation.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webpartmanager.displaymode.aspx