首页 文章

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

提问于
浏览
3

我在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等列表模式 . 我如何能...

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

  • 将网址正确设置为母版页?

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

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

MasterPageFile="~/masterurl/gcmaster.master"

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

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

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

5 回答

  • 0

    Re Masterpage:我想你想要' ~masterurl/gcmaster.master ' . "~"和"master"之间没有"/" .

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

  • 2

    自定义为新项目显示的表单,并将其重定向到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更改链接 .

  • 0

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

    的MasterPageFile = “〜masterurl / default.master”

    的MasterPageFile = “〜masterurl / custom.master”

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

    希望有所帮助 .

  • 1

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

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

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

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

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

    HTH,

    詹姆士

  • 0

    如果你想在各种.aspx页面中重用一个母版页,那么你在WSS中没有一个页面可以让你轻松地做到这一点,所以你最好还是右键单击你的_catalogs / masterpage / gcmaster.master文件在SharePoint Designer中选择“设置为自定义母版页”,或通过PowerShell在服务器上设置它(此处提供的SharePoint脚本 Headers :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"
    

相关问题