SharePoint字段验证程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SharePoint字段验证程序相关的知识,希望对你有一定的参考价值。

  1. <%@ Register TagPrefix="spuc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
  2.  
  3. <spuc:InputFormRequiredFieldValidator ID="UserNameValidator" runat="server" Display="Dynamic" SetFocusOnError="true" ControlToValidate="TextBoxFromEmail" BreakBefore="true" ErrorMessage="Email is required" />
  4.  
  5. <spuc:InputFormRangeValidator ID="AgeValidator" runat="server" Display="Dynamic" SetFocusOnError="true"
  6. ControlToValidate="AgeInputFormTextBox" BreakBefore="true"
  7. Type="Integer" MinimumValue="21" MaximumValue="30"
  8. ErrorMessage="You must be between 21 and 30 years old." />
  9.  
  10. <spuc:InputFormRegularExpressionValidator ID="Validator" runat="server" Display="Dynamic" SetFocusOnError="true"
  11. ControlToValidate="EmailTextBox"
  12. ValidationExpression="^[A-Za-z0-9._%+-][email protected][A-Za-z0-9.-]+.[A-Za-z]{2,4}$"
  13. ErrorMessage="Enter a valid email address." />
  14.  
  15. <spuc:InputFormCustomValidator ID="UsernameCustomValidator" runat="server" Display="Dynamic" SetFocusOnError="true"
  16. ControlToValidate="UsernameTextBox"
  17. OnServerValidate="ValidateUserName"
  18. ErrorMessage="Your user name must be at least 10 characters long (server-side validation)."
  19. ValidateEmptyText="true" />
  20.  
  21. In your code-behind you define the controls as protected class-level variables:
  22.  
  23. protected InputFormTextBox UsernameTextBox;
  24. protected InputFormCustomValidator UsernameCustomValidator;
  25. And you add the server-side validation method. This method accepts 2 incoming arguments: a source object being the control to validate, and a args object having properties as Value and IsValid. The Value property contains the value to validate. Set the IsValid property to true if the validation is successful or set the IsValid property to false if the validation fails.
  26.  
  27. protected void ValidateUserName(object source, ServerValidateEventArgs args)
  28. {
  29. if (args.Value.Length >= 10)
  30. args.IsValid = true;
  31. else
  32. args.IsValid = false;
  33. }

以上是关于SharePoint字段验证程序的主要内容,如果未能解决你的问题,请参考以下文章

如何从sharepoint中的文件夹中获取所有文件?

SharePoint 自定义列表表单不验证必填字段

SharePoint 获取详细Log信息

SharePoint 升级 Web Site 模式

向 SharePoint Webpart 添加必填字段验证器

如何将Excel Web Access Web部件添加到我的sharepoint库中?