覆盖自定义表单模板中的 SharePoint:SaveButton
首先让我澄清一下,并发布已经解释如何覆盖 SaveButton 的文章:
我已阅读并理解它们,我只是不知道如何在我的特定情况下完全实现它:
我有一个自定义渲染模板“CustomRender”,其中包含“真实表单”。真实表单的代码看起来围绕这些行:
<%@ Register TagPrefix="wssuc" TagName="ToolBar"
src="~/_controltemplates/ToolBar.ascx" %>
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="RealForm.ascx.cs" Inherits="CustomNameSpace.CustomForm" %>
<p>Test</p>
<wssuc:ToolBar runat="server" id="toolbar">
<TemplateButtons>
<SharePoint:SaveButton runat="server" />
</TemplateButtons>
</wssuc:ToolBar>
现在我想覆盖这个保存按钮。上面的网站声明我只需要编写另一个覆盖按钮的控件。例如:
public class NewSaveButton: SaveButton
{
protected override bool SaveItem()
{
bool success = base.SaveItem();
RedirectUrl = String.Concat(List.ParentWeb.ServerRelativeUrl, "/",
List.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url, @"?ID=",
ListItem.ID, @"&Source=", ListItem.ParentList.DefaultViewUrl);
return success;
}
}
现在我只是不知道如何在我的其他模板中注册这个模板。我是否不能只覆盖模板后面代码中的 SaveButton - 我该如何做到这一点并稍后引用它?
- 选项一:表单的代码隐藏 (
RealForm.ascx.cs
) - 我可以将覆盖方法放在那里吗?如何在表单中引用该按钮(如何获取
)? - 选项二:另一个仅用于按钮的模板,例如 SaveButton.ascx” - 我如何通过
<%@ Register... %>
引用该模板,即我如何知道PublicKeyToken
等通过功能部署时。这里也是一样:我的目标是为表单获取某种“”控件。
First let me clear the air and post articles which already explain how to override the SaveButton:
- How to override or customize the Sharepoint SaveButton?
- How to override functionality of the Ribbon Save button
- Override SharePoint Save Button to Provide Custom Functionality
I have read those and understood them, I just don't know how to fully implement it in my particular case:
I have a custom rendering template "CustomRender" which includes the "real form". The code for the real form looks something around these lines:
<%@ Register TagPrefix="wssuc" TagName="ToolBar"
src="~/_controltemplates/ToolBar.ascx" %>
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="RealForm.ascx.cs" Inherits="CustomNameSpace.CustomForm" %>
<p>Test</p>
<wssuc:ToolBar runat="server" id="toolbar">
<TemplateButtons>
<SharePoint:SaveButton runat="server" />
</TemplateButtons>
</wssuc:ToolBar>
Now I want to override this save button. The sites above state that I just have to write another control which overrides the button. E.g.:
public class NewSaveButton: SaveButton
{
protected override bool SaveItem()
{
bool success = base.SaveItem();
RedirectUrl = String.Concat(List.ParentWeb.ServerRelativeUrl, "/",
List.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url, @"?ID=",
ListItem.ID, @"&Source=", ListItem.ParentList.DefaultViewUrl);
return success;
}
}
Now I just don't know how to register this template inside my other template. Could I not just override the SaveButton in the Code behind of my template - how would I do that and reference it later on?
- Option one: Code-Behind of the form (
RealForm.ascx.cs
) - can I just put the override method in there? How can I reference the button then in the form (how do I get<NewSaveButton>
)? - Option two: Another template just for the button, e.g. SaveButton.ascx" - how do I reference that via
<%@ Register... %>
, i.e. how do I knowPublicKeyToken
etc. when deployed via a Feature. And same thing here: My goal is to get some kind of "<NewSaveButton>
" control for the form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
执行此操作时,您将创建一个新的服务器控件,因此您需要在页面上(或者在本例中,在模板 .ascx 文件中)注册新控件。
在您的代码文件中,您可以将
ToolboxDataAttribute
添加到类中(仅当您从 Visual Studio 中的工具箱中拖放控件时才需要这样做)现在,您应该能够替换保存按钮,其中包含以下内容:
您基本上是按照 ASP.NET 的规则创建一个新的服务器控件(此处没有发生特定于共享点的内容)。
有关详细信息,请查看此页面:http ://msdn.microsoft.com/en-us/library/yhzc935f(v=VS.85).aspx
You're creating a new server control when you do this, so you'll need to register the new control on the page (or in this case, in the template .ascx file).
In your code file you can to add the
ToolboxDataAttribute
to the class (this is only necessary if you are dragging&dropping the control from the toolbox in visual studio)Now, you should be able to replace the save button on the form with the following:
You're basically creating a new server control following the rules of asp.net (no sharepoint specific stuff is happening here).
For more information, take a look at this page: http://msdn.microsoft.com/en-us/library/yhzc935f(v=VS.85).aspx
在带有 SaveButton 的页面上,您可以执行以下技巧(在我的情况下,保存按钮添加在 DataFormWebPart 的 XSL 标记中):
FindControlRecursive() 扩展实现是
On your page with SaveButton you could do the following trick (in my case save button is added in DataFormWebPart's XSL markup):
The FindControlRecursive() extension implementation is