2011-09-05 66 views
0

我已經創建了一個自定義Share Point 2010 webpart,其中我從用戶獲取輸入,基本上它是一種新的表單。我對數據存儲的預定義列表,我用覆蓋SharePoint:SaveButton單擊事件共享點

<SharePoint:FormField ID="id" runat="server" ControlMode="New" FieldName="name" > 
</SharePoint:FormField> 

和使用

<SharePoint:SaveButton ID="SP_save" runat="server" ControlMode="New" > 
</SharePoint:SaveButton> 

保存表單字段。 它所有工作正常,它需要輸入中的有效數據並顯示正確的驗證消息。 但我有一個問題,因爲我無法訪問SharePoint:SaveButton單擊事件,並且無法將其覆蓋到我的自定義事件

例如,我有一個要求將數據保存在列表中,然後根據輸入執行一些其他任務,所以我該怎麼做

回答

1

您需要創建自定義SaveButton並覆蓋SaveItem方法。

代碼:

namespace CustomOverrideControls 
{ 
    public class CustomSaveButton : SaveButton 
    { 
     protected override void OnInit(EventArgs e) 
     { 
      base.OnInit(e); 
     } 

     protected override bool SaveItem() 
     { 
      // Do the custom code here 
      return base.SaveItem(); 
     } 
    } 
} 

標記:

<CustomOverrideControls:CustomSaveButton ID="SP_save" runat="server" 
    ControlMode="New"> 
</CustomOverrideControls:CustomSaveButton> 

我從文章How to override or customize the SharePoint SaveButton?也包含了下載一個完整的項目上面的例子。

+0

其實我想將用戶重定向到我定義的頁面,所以在saveitem()中,我設置了RedirectUrl,但它不會重定向到我定義的頁面? –

+0

@Saboor Awan:我只需在'base.SaveItem'後調用'Response.Redirect'方法,但也可以嘗試通過添加'?source = http:// [site]/[庫]/CustomRedirectPage.aspx'(http://www.graphicalwonder.com/?p=666)。 –