Sharepoint Web 部件表单验证阻止更新 Web 部件设置 [英] Sharepoint web part form validation blocks updating web part settings

查看:67
本文介绍了Sharepoint Web 部件表单验证阻止更新 Web 部件设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 C# 为 Sharepoint 2007 编写了一个 Web 部件,它有一个字段,该字段使用 RequiredFieldValidator() 验证为必填字段.Web 部件还有一些配置字段(您可以通过单击修改共享 Web 部件"来编辑这些字段).

I have written a web part in C# for Sharepoint 2007 which has a single field which is validated as a required field using RequiredFieldValidator(). The web part also has some configuration fields (ones you edit by clicking on Modify Shared Web Part).

当我对这些字段进行更改并尝试应用它们时,即使我没有提交表单,用户字段的验证也会启动并阻止更新.我只是想提交设置.Web 部件可能会在我们场的一些地方使用,因此网站集管理员需要能够更改设置 - 目前对于这些用户来说这样做不够友好.

When I make changes to these fields and try to apply them, the validation of the user field kicks in and prevents the update, even though I am not submitting the form. I am only trying to submit the settings. The web part may be used in a few places on our farm, so site collection administrators need to be able to change the settings - at the moment it is not friendly enough for these users to do so.

这里是我验证用户字段的地方:

Here is where I validate the user field:

// Validate form field - required field, and max length is 100 characters.
InputFormRequiredFieldValidator messageRequiredValidator = new InputFormRequiredFieldValidator();
messageRequiredValidator.ControlToValidate = txtMessage.ID;
messageRequiredValidator.ErrorMessage = "You must write a message to send!";
messageRequiredValidator.Display = ValidatorDisplay.Dynamic;
messageRequiredValidator.Text = "<img src=\"/_layouts/images/CNSCA16.gif\"/> You must write a message to send.";
tc.Controls.Add(messageRequiredValidator);

这里是我定义配置字段之一的地方:

Here is where I define one of the configuration fields:

private string recipientEmailAddress = "sender@domain.tld";
    [WebBrowsable(true),
    Personalizable(true),
    WebPartStorage(Storage.Shared),
    WebDescription("Email address the form should be sent to"),
    WebDisplayName("Recipient Email Address"),
    SPWebCategoryName("Email Settings")]
    public string RecipientEmailAddress
    {
        get { return recipientEmailAddress; }
        set { recipientEmailAddress = value; }
    }

这是我编写的第一个 Web 部件,因此在如何对用户提交的字段进行管理员配置和验证时,我可能会遗漏一些细节.

This is the first web part I have written, so there may be some subtleties I am missing in how to do admin configuration and validation of user submitted fields.

推荐答案

好的 - 我找到了解决方案的关键.您可以将 validationGroup 属性添加到每个验证器,并添加到按钮导致验证.所以我改变了我的代码以包括:

Ok - I've found the key to this. You can add a validationGroup property to each validator, and to the button that causes the validation. So I changed my code to include:

messageRequiredValidator.validationGroup = "UserInput";

以及与我的提交按钮类似的属性.现在,当我在 ToolPane 中单击 Ok 时,它不会验证 UserInput 验证组.只有当我点击提交按钮时才会发生这种情况.

and a similar property to my submit button. Now when I click on Ok in the ToolPane, it doesn't validate the UserInput validation group. That only happens when I click on my Submit button.

这篇关于Sharepoint Web 部件表单验证阻止更新 Web 部件设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆