简体   繁体   English

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

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

I have created a custom list in a SharePoint site and generated a Visual Studio 2008 project using SharePoint Solution Generator. 我在SharePoint网站中创建了一个自定义列表,并使用SharePoint Solution Generator生成了一个Visual Studio 2008项目。 I can package this as a feature and install it. 我可以将其打包为一个功能并安装它。 It runs fine on my server. 它在我的服务器上正常运行。

After testing this out, I've been able to add a custom masterpage to the feature which is deployed to the _catalogs/masterpage folder. 在测试完之后,我已经能够将自定义母版页添加到部署到_catalogs / masterpage文件夹的功能部件中。 Here it is: 这里是:

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

Now that I have a custom masterpage in my site, I would like to have this used for the creation of new items. 既然我的网站中有自定义母版页,我想将其用于创建新项目。 But I don't want to have to set the master from SharePoint Designer. 但我不想从SharePoint Designer中设置主服务器。

Going back to the generated solution, it has NewForm.aspx etc. with the list schema. 回到生成的解决方案,它具有NewForm.aspx等列表模式。 How do I... 我如何...

  1. Customize the form that is displayed for new items, and have it redirect to a thankyou.aspx page rather than showing all the list items? 自定义为新项目显示的表单, 并将其重定向到thankyou.aspx页面而不是显示所有列表项?
  2. Set the url to the master page correctly? 将网址正确设置为母版页?

I'm lost on point number 1. Do I need to create a custom webpart and embed that in NewForm.aspx? 我在第1点丢失了。我是否需要创建一个自定义webpart并将其嵌入NewForm.aspx中?

On point 2 I have made some headway but have run into an issue. 在第2点,我取得了一些进展,但遇到了一个问题。 If I set the master like this in my NewForm.aspx... 如果我在NewForm.aspx中设置这样的主人......

 MasterPageFile="~/masterurl/gcmaster.master"

It will install OK, but when I hit the site I get an error because ~ is not allowed in the URL. 它将安装好,但是当我点击该网站时,我收到一个错误,因为在URL中不允许〜。 If I use _catalogs/masterpage in the directive, it will not find the master because the URL is relative. 如果我在指令中使用_catalogs / masterpage,它将找不到master,因为URL是相对的。 Only this code seems to work: 只有这个代码似乎有效:

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

What's the best practice way of setting the master page file in SharePoint, when deploying a custom feature/solution? 在部署自定义功能/解决方案时,在SharePoint中设置母版页文件的最佳实践方法是什么?

Re Masterpage: I think you want ' ~masterurl/gcmaster.master '. Re Masterpage:我想你想要' ~masterurl/gcmaster.master '。 no "/" between the "~" and "master". “〜”和“主人”之间没有“/”。

Re NewForm: You can create your own code-behind page for NewForm.aspx, change the Inherits attribute to your own class. Re NewForm:您可以为NewForm.aspx创建自己的代码隐藏页面,将Inherits属性Inherits为您自己的类。 I think I would start by having my custom code behind inherit from SharePoint.SharePoint.WebPartPages.WebPartPage , and go from there. 我想我首先要从SharePoint.SharePoint.WebPartPages.WebPartPage继承我的自定义代码,然后从那里开始。

Customize the form that is displayed for new items, and have it redirect to a thankyou.aspx page rather than showing all the list items? 自定义为新项目显示的表单,并将其重定向到thankyou.aspx页面而不是显示所有列表项?

The SIMPLEST answer, is, change the "Add New Item" link to add a source URL for your thank you page. SIMPLEST答案是,更改“添加新项目”链接以添加感谢页面的源URL。 For example, instead of (I had to leave out the http): 例如,而不是(我不得不遗漏http):

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

you change it to: 你把它改成:

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

When the user click Submit from the NewForm page, they will be redirected to ThankYou.aspx. 当用户从NewForm页面单击Submit时,它们将被重定向到ThankYou.aspx。

You will probably have to use SharePoint Designer to change the link, however. 但是,您可能必须使用SharePoint Designer更改链接。

Override the OnPreInit event on the webpage, and in there put this line in: 覆盖网页上的OnPreInit事件,并将此行放入:

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

(if you're using the custom master page) (如果您使用的是自定义母版页)

If you're using the default master page, use the following line: 如果您使用的是默认母版页,请使用以下行:

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

HTH, HTH,

James 詹姆士

If you want to reuse a master page across a variety of .aspx pages, then you're better off setting it as the Custom Master Page. 如果要在各种.aspx页面中重复使用母版页,那么最好将其设置为自定义母版页。 There's no page in WSS that lets you do this easily, so you're better off either Right-Clicking your _catalogs/masterpage/gcmaster.master file in SharePoint Designer and choosing Set as Custom Master Page, or setting it on the server through PowerShell (SharePoint script header available here: http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/Post.aspx?ID=7 ) 在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()

Then in the @Page directive of your .aspx page, you can set: 然后在.aspx页面的@Page指令中,您可以设置:

MasterPageFile="~/masterurl/custom.master"

Bear in mind that this makes all .aspx pages in your site that reference "~/masterurl/custom.master" use your gcmaster.master page. 请记住,这会使您网站中引用“〜/ masterurl / custom.master”的所有.aspx页面都使用您的gcmaster.master页面。

Alternatively, you could skip all that and for your .aspx page simply include a @Page directive that looks like this: 或者,您可以跳过所有这些,并且对于.aspx页面,只需包含一个如下所示的@Page指令:

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

Best way to do it is open up NewForm.aspx in SharePoint Designer, change: 最好的方法是在SharePoint Designer中打开NewForm.aspx,更改:

MasterPageFile="~masterurl/default.master" 的MasterPageFile = “〜masterurl / default.master”

to

MasterPageFile="~masterurl/custom.master" 的MasterPageFile = “〜masterurl / custom.master”

This will obviously edit the current instance but if you want to deploy this with a site def or feature then you need to create and NewForm.aspx page within the same folder as schema.xml in your list instance folder. 这显然会编辑当前实例,但是如果要使用站点def或功能部署它,则需要在列表实例文件夹中与schema.xml相同的文件夹中创建和NewForm.aspx页面。

Hope that helps. 希望有所帮助。

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

相关问题 如何在SharePoint 2007的NewForm.aspx上添加自定义列 - How can I add custome column on NewForm.aspx on SharePoint 2007 更改SharePoint 2010自定义Newform.aspx中字段的“必需”属性 - Changing “required” property of a field in SharePoint 2010 custom Newform.aspx 如何基于输入单选按钮在NewForm.aspx中设置SharePoint列表字段? - How do I set a SharePoint list field in NewForm.aspx based on an input radio button? SharePoint 2013 NewForm.aspx上的其他按钮 - Extra Buttons on SharePoint 2013 NewForm.aspx 在线修改NewForm.aspx Sharepoint - Modify NewForm.aspx Sharepoint Online SharePoint 2007 列表中自定义 NewForm.aspx 和 EditForm.aspx 之间的差异 - Differences between a custom NewForm.aspx and EditForm.aspx in a SharePoint 2007 List 如何用SP2007以编程方式自定义editform.aspx / newform.aspx? - How to programmatically customize editform.aspx/newform.aspx with SP2007? 如何从SharePoint中的子列表NewForm.aspx表单访问父列表Editform.aspx? - How to access Parent List Editform.aspx from child list NewForm.aspx form in SharePoint? Sharepoint-捕获NewForm.aspx / Edit.aspx的保存事件 - Sharepoint - Capture save event of NewForm.aspx/Edit.aspx 如何在newform.aspx上使用SP的JavaScript客户端对象模型从当前列表中获取项目及其附件? - how can I get an item and it's attachments from the current list using SP's JavaScript Client Object Model on newform.aspx?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM