繁体   English   中英

SharePoint - 如何在自定义功能中自定义NewForm.aspx?

[英]SharePoint - How can I customize NewForm.aspx in custom feature?

我在SharePoint网站中创建了一个自定义列表,并使用SharePoint Solution Generator生成了一个Visual Studio 2008项目。 我可以将其打包为一个功能并安装它。 它在我的服务器上正常运行。

在测试完之后,我已经能够将自定义母版页添加到部署到_catalogs / masterpage文件夹的功能部件中。 这里是:

<Elements Id="2196306F-3F37-40b5-99CF-42E89B93888A" xmlns="http://schemas.microsoft.com/sharepoint/">
    <Module Name="DefaultMasterPage" Url="_catalogs/masterpage" RootWebOnly="FALSE">
      <File Url="gcbranding.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />
    </Module>
</Elements>

既然我的网站中有自定义母版页,我想将其用于创建新项目。 但我不想从SharePoint Designer中设置主服务器。

回到生成的解决方案,它具有NewForm.aspx等列表模式。 我如何...

  1. 自定义为新项目显示的表单, 并将其重定向到thankyou.aspx页面而不是显示所有列表项?
  2. 将网址正确设置为母版页?

我在第1点丢失了。我是否需要创建一个自定义webpart并将其嵌入NewForm.aspx中?

在第2点,我取得了一些进展,但遇到了一个问题。 如果我在NewForm.aspx中设置这样的主人......

 MasterPageFile="~/masterurl/gcmaster.master"

它将安装好,但是当我点击该网站时,我收到一个错误,因为在URL中不允许〜。 如果我在指令中使用_catalogs / masterpage,它将找不到master,因为URL是相对的。 只有这个代码似乎有效:

MasterPageFile="../../_catalogs/masterpage/gcmaster.master"

在部署自定义功能/解决方案时,在SharePoint中设置母版页文件的最佳实践方法是什么?

Re Masterpage:我想你想要' ~masterurl/gcmaster.master '。 “〜”和“主人”之间没有“/”。

Re NewForm:您可以为NewForm.aspx创建自己的代码隐藏页面,将Inherits属性Inherits为您自己的类。 我想我首先要从SharePoint.SharePoint.WebPartPages.WebPartPage继承我的自定义代码,然后从那里开始。

自定义为新项目显示的表单,并将其重定向到thankyou.aspx页面而不是显示所有列表项?

SIMPLEST答案是,更改“添加新项目”链接以添加感谢页面的源URL。 例如,而不是(我不得不遗漏http):

www.yoursite.com/Lists/Links/NewForm.aspx

你把它改成:

www.yoursite.com/Lists/Links/NewForm.aspx?Source=www.yoursite.com/ThankYou.aspx

当用户从NewForm页面单击Submit时,它们将被重定向到ThankYou.aspx。

但是,您可能必须使用SharePoint Designer更改链接。

覆盖网页上的OnPreInit事件,并将此行放入:

this.MasterPageFile = SPContext.Current.Web.CustomMasterUrl;

(如果您使用的是自定义母版页)

如果您使用的是默认母版页,请使用以下行:

this.MasterPageFile =  SPContext.Current.Web.MasterUrl;

HTH,

詹姆士

如果要在各种.aspx页面中重复使用母版页,那么最好将其设置为自定义母版页。 在WSS中没有可以轻松完成此任务的页面,因此您最好右键单击SharePoint Designer中的_catalogs / masterpage / gcmaster.master文件并选择“设置为自定义母版页”,或通过PowerShell在服务器上进行设置(此处提供的SharePoint脚本标题为: http//sharepoint.microsoft.com/blogs/zach/Lists/Posts/Post.aspx?ID = 7

$web = Get-SPWeb("http://mysiteurl")
$web.CustomMasterUrl = "_catalogs/masterpage/gcmaster.master"
$web.Update()

然后在.aspx页面的@Page指令中,您可以设置:

MasterPageFile="~/masterurl/custom.master"

请记住,这会使您网站中引用“〜/ masterurl / custom.master”的所有.aspx页面都使用您的gcmaster.master页面。

或者,您可以跳过所有这些,并且对于.aspx页面,只需包含一个如下所示的@Page指令:

MasterPageFile="~/site/_catalogs/masterpage/gcmaster.master"

最好的方法是在SharePoint Designer中打开NewForm.aspx,更改:

的MasterPageFile = “〜masterurl / default.master”

的MasterPageFile = “〜masterurl / custom.master”

这显然会编辑当前实例,但是如果要使用站点def或功能部署它,则需要在列表实例文件夹中与schema.xml相同的文件夹中创建和NewForm.aspx页面。

希望有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM