我已經在C#中爲Sharepoint 2007編寫了一個Web部件,該部件包含一個使用RequiredFieldValidator()
驗證爲必填字段的單個字段。 Web部件還具有一些配置字段(通過單擊修改共享Web部件編輯的字段)。Sharepoint Web部件表單驗證塊更新Web部件設置
當我對這些字段進行更改並嘗試應用它們時,即使我沒有提交表單,用戶字段的驗證也會啓動並阻止更新。我只是想提交設置。 Web部分可能會在我們的農場的一些地方使用,因此網站集管理員需要能夠更改設置 - 目前它對這些用戶來說不夠友好。
這裏是我驗證用戶字段:
// 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);
這裏就是我定義配置字段之一:
private string recipientEmailAddress = "[email protected]";
[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部件時驗證編輯器窗格字段 - 這是否也禁用了? – dunxd 2010-12-10 11:10:41