简体   繁体   English

SharePoint 2007 列表中自定义 NewForm.aspx 和 EditForm.aspx 之间的差异

[英]Differences between a custom NewForm.aspx and EditForm.aspx in a SharePoint 2007 List

I'm working in a list with a custom NewForm.aspx and a custom EditForm.aspx, which I've called New.aspx and Edit.aspx.我正在处理一个包含自定义 NewForm.aspx 和自定义 EditForm.aspx 的列表,我将它们称为 New.aspx 和 Edit.aspx。 I'm far from a SharePoint expert, but it looks like the only differences between the two files are the miscellaneous ControlMode attributes set throughout the file.我远非 SharePoint 专家,但看起来这两个文件之间的唯一区别是在整个文件中设置的其他 ControlMode 属性。

ControlMode="New" for New.aspx and ControlMode="Edit" for Edit.aspx ControlMode="New" 用于 New.aspx 和 ControlMode="Edit" 用于 Edit.aspx

As a test, I took the code from my New.aspx and copied it into my Edit.aspx and just changed the ControlMode attributes to 'Edit.'作为测试,我从我的 New.aspx 中获取代码并将其复制到我的 Edit.aspx 中,并将 ControlMode 属性更改为“编辑”。 Everything seems to be working fine.一切似乎都运行良好。 So what I'd like to do is just use one file rather than a separate one for New and Edit.所以我想做的只是使用一个文件而不是一个单独的文件来新建和编辑。 I'm not sure if this is possible, but the first step I took was to create an XSL variable:我不确定这是否可能,但我采取的第一步是创建一个 XSL 变量:

<xsl:variable name="ControlMode" select="'Edit'" />

Then I can do something like this:然后我可以做这样的事情:

<xsl:choose>
  <xsl:when test="$ControlMode = 'New'">
    <SharePoint:AttachmentUpload runat="server" ControlMode="New"/>
    <SharePoint:ItemHiddenVersion runat="server" ControlMode="New"/>
  </xsl:when>
  <xsl:when test="$ControlMode = 'Edit'">
    <SharePoint:AttachmentUpload runat="server" ControlMode="Edit"/>
    <SharePoint:ItemHiddenVersion runat="server" ControlMode="Edit"/>
  </xsl:when>
</xsl:choose>

My form is still working fine at this point, but it's still two different files.此时我的表单仍然可以正常工作,但它仍然是两个不同的文件。 So the question is, does anyone know a way I can populate the xsl:variable dynamically so that I can specify just one file for new and edit modes?所以问题是,有谁知道我可以动态填充 xsl:variable 的方法,以便我可以只为新模式和编辑模式指定一个文件?

Thanks in advance!提前致谢!

I'm not sure if answering my own question is correct etiquette or not, but I found my answer... turns out to be much simpler than I thought.我不确定回答我自己的问题是否是正确的礼仪,但我发现我的答案......结果比我想象的要简单得多。

As I was reading Brian's reply, it occurred to me that editing a post changes the query string.在阅读 Brian 的回复时,我突然想到编辑帖子会更改查询字符串。 There's an ID specified of course.当然有指定的ID。 So I started looking for the best way to parse the query string.所以我开始寻找解析查询字符串的最佳方法。 That's when I realized that this is already done for me in the ParameterBindings:那时我意识到这已经在 ParameterBindings 中为我完成了:

<ParameterBinding Name="ListItemId" Location="QueryString(ID)" DefaultValue="0"/>

The xsl:param tag was not specified however, so I added this to the top of my xsl:stylesheet:但是 xsl:param 标记没有被指定,所以我将它添加到我的 xsl:stylesheet 的顶部:

<xsl:param name="ListItemId"></xsl:param>

Then, instead of using the ControlMode variable that I created in my original post, I can now test directly against the ListItemID:然后,我现在可以直接针对 ListItemID 进行测试,而不是使用我在原始帖子中创建的 ControlMode 变量:

<xsl:choose>
  <xsl:when test="$ListItemId = '0' or not($ListItemId)">
    <SharePoint:AttachmentUpload runat="server" ControlMode="New"/>
    <SharePoint:ItemHiddenVersion runat="server" ControlMode="New"/>
  </xsl:when>
  <xsl:otherwise>
    <SharePoint:AttachmentUpload runat="server" ControlMode="Edit"/>
    <SharePoint:ItemHiddenVersion runat="server" ControlMode="Edit"/>
  </xsl:otherwise>
</xsl:choose>

Basically, I'm just checking for a 0 value (the default specified in the ParameterBinding) and showing different controls.基本上,我只是检查 0 值(在 ParameterBinding 中指定的默认值)并显示不同的控件。

I've been testing this for a bit this afternoon, and thus far it works brilliantly.今天下午我已经对此进行了一些测试,到目前为止它运行良好。

the built in sharepoint controls will attempt to function differently based on the control mode defined.内置的 sharepoint 控件将根据定义的控制模式尝试不同的 function。 Obviously if it is edit, then it will attempt to not only just render a control but populated that control with the current value.显然,如果它是编辑的,那么它不仅会尝试渲染控件,还会尝试使用当前值填充该控件。 If the mode is new, it will simply render the control without a predefined value.如果模式是新的,它将简单地呈现没有预定义值的控件。 There's a lot more to it but that's the high level overview.它还有很多内容,但这是高级概述。

If you are using custom new vs edit form I'd personally keep them seperate for the organizational purposes.如果您使用自定义的新表单和编辑表单,我个人会出于组织目的将它们分开。 An easy solution would be to use an XSL include after you have defined the variable inside each pages form.一个简单的解决方案是在每个页面表单中定义变量后使用 XSL 包含。

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

相关问题 如何从SharePoint中的子列表NewForm.aspx表单访问父列表Editform.aspx? - How to access Parent List Editform.aspx from child list NewForm.aspx form in SharePoint? 如何用SP2007以编程方式自定义editform.aspx / newform.aspx? - How to programmatically customize editform.aspx/newform.aspx with SP2007? 为什么SharePoint 2010计算字段显示在EditForm.aspx和newForm.aspx中 - Why SharePoint 2010 Calculated fields show in EditForm.aspx and newForm.aspx 是否可以在2007年使用模式弹出窗口访问共享点列表newform.aspx - is it possible to access the sharepoint list newform.aspx using modal popup in 2007 SharePoint - 如何在自定义功能中自定义NewForm.aspx? - SharePoint - How can I customize NewForm.aspx in custom feature? 更改SharePoint 2010自定义Newform.aspx中字段的“必需”属性 - Changing “required” property of a field in SharePoint 2010 custom Newform.aspx sharepoint自定义EditForm.aspx无法读取正确的项目ID? - sharepoint custom EditForm.aspx not reading the correct item ID? SharePoint 2013 NewForm.aspx上的其他按钮 - Extra Buttons on SharePoint 2013 NewForm.aspx 在线修改NewForm.aspx Sharepoint - Modify NewForm.aspx Sharepoint Online 将JavaScript插入sharepoint editform.aspx - Inserting javascript into sharepoint editform.aspx
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM