开发者

Sharepoint item updating event - cancel event back to editform page?

I have an event receiver for a content type to validate some data in the ItemUpdating event. If I cancel the event (some of the data isn't valid for example), I set the properties cancel to true:

properties.Cancel = true;
properties.ErrorMessage = "...";

SharePoint cancels the updating event ok, but shows the standard SharePoint error page (with the specified message). Only problem is, I've got a complaint that this isn't actually very useful - we should return to the EditForm page so the details can be updated.

Has anyone done this, is there an easy way? The only suggestion I've had is that I can implement my ow开发者_如何转开发n error page, but that's sounding quite a heavy solution to a (theoretically) simple process.


You could try to output HTML code (which includes javascript as well) in the ErrorMessage. BUT even if you do, the problem is that you have no safe way back to the data the user has entered. Either you make a HTTP/301 redirect and then it's a new page load, or you make the client go history.back() with JavaScript and then the browser may reload the page.

The official way of doing this is that you create a list definition and customize the list template. Then you edit the edit form template and include as many ASP.Net validator controls as needed. Then, implement the server side logic as you need. This article explains the technique: http://msdn.microsoft.com/en-us/library/aa543922.aspx

EDIT: To attach a custom control for editing of a specific contenttype, you add an XmlDocuments section to your ContentType definition. For instance, like this

<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>
  .......

Then you create your own yoursolution_controltemplates.ascx file, which contains as well such blocks:"

<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>


You can try to redirect using CopyUtil : http://weblogs.asp.net/jan/archive/2008/02/26/copyutil-aspx-a-little-sharepoint-gem.aspx

link = "http://yoursite/_layouts/CopyUtil.aspx?Use=id&Action=dispform&ItemId=X&ListId=X&WebId=X&SiteId=X";

Page.Response.Redirect(link)

maybe this will work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜