您可以尝试在 ErrorMessage 中输出 HTML 代码(也包括 javascript)。但即使你这样做了,问题是你没有安全的方法返回用户输入的数据。要么进行 HTTP/301 重定向,然后加载新页面,要么让客户端history.back()
使用 JavaScript,然后浏览器可能会重新加载页面。
执行此操作的官方方法是创建列表定义并自定义列表模板。然后编辑编辑表单模板并根据需要包含尽可能多的 ASP.Net 验证器控件。然后,根据需要实现服务器端逻辑。这篇文章解释了这项技术:http: //msdn.microsoft.com/en-us/library/aa543922.aspx
编辑:要附加自定义控件以编辑特定的内容类型,请将 XmlDocuments 部分添加到 ContentType 定义中。例如,像这样
<ContentType
..........
<XmlDocuments>
<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<Display>ContentTypeName_DispForm</Display>
<Edit>ContentTypeName_EditForm</Edit>
<New>ContentTypeName_NewForm</New>
</FormTemplates>
</XmlDocument>
</XmlDocuments>
.......
然后你创建你自己的yoursolution_controltemplates.ascx
文件,其中也包含这样的块:"
<SharePoint:RenderingTemplate ID="ContentTypeName_DispForm" runat="server">
<Template>
<!-- put whatever controls you need here, we typically create a
separate custom control which implements everything-->
</Template>
</SharePoint:RenderingTemplate>