如何在自定义编辑表单上检索 ListFormWebPart 的列表 ID?

发布于 2025-01-01 03:53:48 字数 5615 浏览 3 评论 0原文

我有一个非常基本的自定义编辑表单,一个带有代码的 aspx。它是标准编辑表单的直接副本,带有一些附加的 JavaScript。 我用设计师(呃)打开它并直接复制它。 问题是ListFormWebPart需要列表id,我试图获取它,但没有任何运气。

它不允许我调试,我基本上想知道我是否完全关闭并且应该以不同的方式处理这个问题或者我是否错过了一些关键的东西?

<WebPartPages:WebPartZone runat="server" FrameType="None" ID="Main" Title="loc:Main"><ZoneTemplate>
    <WebPartPages:ListFormWebPart ID="ListFormWebPart" runat="server" __MarkupType="xmlmarkup" WebPart="true" __WebPartId="{B1433CAB-755A-4E8C-A35E-629AD2C5BB67}" >
        <WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
          <Title>Dokument</Title>
          <FrameType>Default</FrameType>
          <Description />
          <IsIncluded>true</IsIncluded>
          <PartOrder>2</PartOrder>
          <FrameState>Normal</FrameState>
          <Height />
          <Width />
          <AllowRemove>true</AllowRemove>
          <AllowZoneChange>true</AllowZoneChange>
          <AllowMinimize>true</AllowMinimize>
          <AllowConnect>true</AllowConnect>
          <AllowEdit>true</AllowEdit>
          <AllowHide>true</AllowHide>
          <IsVisible>true</IsVisible>
          <DetailLink />
          <HelpLink />
          <HelpMode>Modeless</HelpMode>
          <Dir>Default</Dir>
          <PartImageSmall />
          <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
          <PartImageLarge />
          <IsIncludedFilter />
          <ExportControlledProperties>true</ExportControlledProperties>
          <ConnectionID>00000000-0000-0000-0000-000000000000</ConnectionID>
          <ID>g_b1433cab_755a_4e8c_a35e_629ad2c5bb67</ID>

          <ListName xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm"> <%=ListId%> </ListName>
          <ListId xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm"> <%=ListId%> </ListId>

          <PageType xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">PAGE_EDITFORM</PageType>
          <FormType xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">6</FormType>
          <ControlMode xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">Edit</ControlMode>
          <ViewFlag xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">1048576</ViewFlag>
          <ViewFlags xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">Default</ViewFlags>
          <ListItemId xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">0</ListItemId>
        </WebPart>
    </WebPartPages:ListFormWebPart>
</ZoneTemplate></WebPartPages:WebPartZone>

这是后面的小代码:

public partial class RKEditForm : LayoutsPageBase
{
    public string ListId { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        Debugger.Launch();
        ListId = Request.QueryString["List"];
        if (string.IsNullOrEmpty(ListId))
        {
            ListId = "123";
        }
    }
}

这是 sharepoint 发送的请求:(在 uls 中拾取)

Name=Request (GET:http://rkdhs-a:80/_layouts/RK.Dhs/RKEditForm.aspx?List=12cfe831%2D9c9d%2D4393%2D85dc%2Dd522440035ca&ID=4&Source=http%3A%2F%2Frkdhs%2Da%2FDokument%2FForms%2FAllItems%2Easpx&RootFolder=%2FDokument&ContentTypeId=0x01010053E1D612BA3F4E21AA250ECD751942B3004C051FA1C7EDB047A5DE0AABD0672600&IsDlg=1)

并且我不断收到此异常:

System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).   
 at System.Guid..ctor(String g)    
 at Microsoft.SharePoint.WebPartPages.ListFormWebPart.get_ItemContext()    
 at Microsoft.SharePoint.WebPartPages.ListFormWebPart.EnsureList()    
 at Microsoft.SharePoint.WebPartPages.ListFormWebPart.EnsureListAndForm()    
 at Microsoft.SharePoint.WebPartPages.ListFormWebPart.UseLegacyForm()    
 at Microsoft.SharePoint.WebPartPages.ListFormWebPart.CreateChildControls()    
 at System.Web.UI.Control.EnsureChildControls()    
 at System.Web.UI.WebControls.WebParts.Part.get_Controls()    
 at System.Web.UI.Control.SetRenderMethodDelegate(RenderMethod renderMethod)    
 at ASP._layouts_rk_dhs_rkeditform_aspx.__BuildControlListFormWebPart()    
 at ASP._layouts_rk_dhs_rkeditform_aspx.__BuildControl__control24(Control __ctrl)    
 at System.Web.UI.WebControls.WebParts.WebPartZone.GetInitialWebParts()    
 at System.Web.UI.WebControls.WebParts.WebPartManager.RegisterZone(WebZone zone)    
 at System.Web.UI.WebControls.WebParts.WebPartZone.OnInit(EventArgs e)    
 at Microsoft.SharePoint.WebPartPages.WebPartZone.OnInit(EventArgs e)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

I have a very basic custom edit form, an aspx with code behind. It is a direct copy of the standard edit form with some additional javascripts.
I opened it up with designer(urgh) and copied it straight off. Problem is that the ListFormWebPart needs the list id, which i'm trying to fetch without any luck.

It won't let me debug and i'm basically wondering if i'm totally off and should approach this differently or am i missing something critical?

<WebPartPages:WebPartZone runat="server" FrameType="None" ID="Main" Title="loc:Main"><ZoneTemplate>
    <WebPartPages:ListFormWebPart ID="ListFormWebPart" runat="server" __MarkupType="xmlmarkup" WebPart="true" __WebPartId="{B1433CAB-755A-4E8C-A35E-629AD2C5BB67}" >
        <WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
          <Title>Dokument</Title>
          <FrameType>Default</FrameType>
          <Description />
          <IsIncluded>true</IsIncluded>
          <PartOrder>2</PartOrder>
          <FrameState>Normal</FrameState>
          <Height />
          <Width />
          <AllowRemove>true</AllowRemove>
          <AllowZoneChange>true</AllowZoneChange>
          <AllowMinimize>true</AllowMinimize>
          <AllowConnect>true</AllowConnect>
          <AllowEdit>true</AllowEdit>
          <AllowHide>true</AllowHide>
          <IsVisible>true</IsVisible>
          <DetailLink />
          <HelpLink />
          <HelpMode>Modeless</HelpMode>
          <Dir>Default</Dir>
          <PartImageSmall />
          <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
          <PartImageLarge />
          <IsIncludedFilter />
          <ExportControlledProperties>true</ExportControlledProperties>
          <ConnectionID>00000000-0000-0000-0000-000000000000</ConnectionID>
          <ID>g_b1433cab_755a_4e8c_a35e_629ad2c5bb67</ID>

          <ListName xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm"> <%=ListId%> </ListName>
          <ListId xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm"> <%=ListId%> </ListId>

          <PageType xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">PAGE_EDITFORM</PageType>
          <FormType xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">6</FormType>
          <ControlMode xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">Edit</ControlMode>
          <ViewFlag xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">1048576</ViewFlag>
          <ViewFlags xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">Default</ViewFlags>
          <ListItemId xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">0</ListItemId>
        </WebPart>
    </WebPartPages:ListFormWebPart>
</ZoneTemplate></WebPartPages:WebPartZone>

And here is the small code behind:

public partial class RKEditForm : LayoutsPageBase
{
    public string ListId { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        Debugger.Launch();
        ListId = Request.QueryString["List"];
        if (string.IsNullOrEmpty(ListId))
        {
            ListId = "123";
        }
    }
}

and this is the request that sharepoint sends: (picked up in uls)

Name=Request (GET:http://rkdhs-a:80/_layouts/RK.Dhs/RKEditForm.aspx?List=12cfe831%2D9c9d%2D4393%2D85dc%2Dd522440035ca&ID=4&Source=http%3A%2F%2Frkdhs%2Da%2FDokument%2FForms%2FAllItems%2Easpx&RootFolder=%2FDokument&ContentTypeId=0x01010053E1D612BA3F4E21AA250ECD751942B3004C051FA1C7EDB047A5DE0AABD0672600&IsDlg=1)

and i keep getting this exception:

System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).   
 at System.Guid..ctor(String g)    
 at Microsoft.SharePoint.WebPartPages.ListFormWebPart.get_ItemContext()    
 at Microsoft.SharePoint.WebPartPages.ListFormWebPart.EnsureList()    
 at Microsoft.SharePoint.WebPartPages.ListFormWebPart.EnsureListAndForm()    
 at Microsoft.SharePoint.WebPartPages.ListFormWebPart.UseLegacyForm()    
 at Microsoft.SharePoint.WebPartPages.ListFormWebPart.CreateChildControls()    
 at System.Web.UI.Control.EnsureChildControls()    
 at System.Web.UI.WebControls.WebParts.Part.get_Controls()    
 at System.Web.UI.Control.SetRenderMethodDelegate(RenderMethod renderMethod)    
 at ASP._layouts_rk_dhs_rkeditform_aspx.__BuildControlListFormWebPart()    
 at ASP._layouts_rk_dhs_rkeditform_aspx.__BuildControl__control24(Control __ctrl)    
 at System.Web.UI.WebControls.WebParts.WebPartZone.GetInitialWebParts()    
 at System.Web.UI.WebControls.WebParts.WebPartManager.RegisterZone(WebZone zone)    
 at System.Web.UI.WebControls.WebParts.WebPartZone.OnInit(EventArgs e)    
 at Microsoft.SharePoint.WebPartPages.WebPartZone.OnInit(EventArgs e)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Control.InitRecursive(Control namingContainer)    
 at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

乞讨 2025-01-08 03:53:48

通过大量试验解决了这个问题,并幸运地偶然发现了这个网站:
http://blogs .sharepointdam.com/jen/archive/2009/10/12/custom-list-forms-with-code-behind.aspx

基本添加OnInit="Lfwp_OnInit" 添加到 webpart 定义中,

<WebPartPages:ListFormWebPart ID="ListFormWebPart1" OnInit="Lfwp_OnInit" webpart="true" runat="server" __WebPartId="{51C3F707-B5E4-408B-9ED8-9AA8C394ADB6}">

删除了这些:

<ListName xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm"> <%=ListId%> </ListName>
<ListId xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm"> <%=ListId%> </ListId>

并将其添加到我的代码隐藏中:

protected void Lfwp_OnInit(object sender, EventArgs e)
    {
        string listId = Page.Request.QueryString["List"];
        string itemId = Page.Request.QueryString["ID"];

        ListFormWebPart lfwp = (ListFormWebPart)sender;
        lfwp.ListName = listId;
        lfwp.ListItemId = Convert.ToInt32(itemId);
    }

Jen(我发布的博客)描述了该问题并很好地解决了:

那么问题出在哪里呢? ListFormWebPart 非常灵活
可以动态呈现自身的编程艺术
自动,具体取决于要显示的列表、内容类型和列
显示,但它不检索 ListName 和 ListItemId
自动从 Page.REQUEST 中。好吧,我们可以用
代码隐藏,但这不是问题;-) 问题是
在 OnPreInit 事件期间控件不可用来设置这些
属性,以及在触发 OnInit 事件处理程序之前 SharePoint
已经抛出异常,表明找不到任何项目
指定的列表和 itemId ...Duhh!
好吧,解决方案实际上(就像生活中的大多数事情一样)微不足道:
OnInit 事件在为页面触发之前先在控件上触发。
因此,不仅添加代码隐藏事件处理程序很重要
在页面级别以及 Web 部件本身:

我确实设法使用以下行在 aspx 内设置 ListID,但 ListName 不起作用..尝试了各种类型的转换、转换和技巧,但没有成功,所以最后我选择了代码隐藏解决方案。

<% ListFormWebPart.ListId = new Guid(Request.QueryString["List"]) %>
<% ListFormWebPart.ListName = Request.QueryString["List"] %>

Solved it with alot of trials some elbow grease and after luckily stumbling across this site:
http://blogs.sharepointdam.com/jen/archive/2009/10/12/custom-list-forms-with-code-behind.aspx

Basically added OnInit="Lfwp_OnInit" to the webpart definition, removed

<WebPartPages:ListFormWebPart ID="ListFormWebPart1" OnInit="Lfwp_OnInit" webpart="true" runat="server" __WebPartId="{51C3F707-B5E4-408B-9ED8-9AA8C394ADB6}">

removed these:

<ListName xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm"> <%=ListId%> </ListName>
<ListId xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm"> <%=ListId%> </ListId>

and added this to my code-behind:

protected void Lfwp_OnInit(object sender, EventArgs e)
    {
        string listId = Page.Request.QueryString["List"];
        string itemId = Page.Request.QueryString["ID"];

        ListFormWebPart lfwp = (ListFormWebPart)sender;
        lfwp.ListName = listId;
        lfwp.ListItemId = Convert.ToInt32(itemId);
    }

Jen(the blog i posted) described the issue and sol well with:

So, where's the problem? The ListFormWebPart is an incredibly flexible
piece of programming art that can render itself on the fly
automatically, depending on what list, content type and columns are to
be displayed, BUT it does not retrieve the ListName and ListItemId
from the Page.REQUEST automatically. Alright, we can do that with the
code-behind, but that's NOT the problem ;-) The problem is that the
control isn't available during the OnPreInit event to set these
properties, and before the OnInit event handler gets fired SharePoint
already throws an exception stating that no item could be found for
the list and itemId specified ...Duhh!
Well, the solution is actually (as most things in life) trivial: the
OnInit event fires on the controls before it fires for the page.
Therefore it is important to add a code-behind event handler not only
at the page level but also for the Web Part itself:

I did manage to set the ListID inside the aspx using the following line, but the ListName wouldn't work.. tried all sorts of castings, converts and tricks but with no success so in the end i settled for the code-behind solution.

<% ListFormWebPart.ListId = new Guid(Request.QueryString["List"]) %>
<% ListFormWebPart.ListName = Request.QueryString["List"] %>
夏末的微笑 2025-01-08 03:53:48

我无法代表您的其余代码或您正在尝试执行的操作,但您可能需要解码列表 id 才能进一步使用此方法。

String DecodedListId = Server.UrlDecode(ListId);

I can't speak for the rest of your code or what you are trying to do but you probably need to decode the list id to get further ahead with this approach.

String DecodedListId = Server.UrlDecode(ListId);
一身骄傲 2025-01-08 03:53:48

ListViewWebPart 需要一个 GUID,而您要为其提供一个三位数。您是否正在尝试传递项目 ID?列表 ID 看起来像这样:{880B8CC4-A1C4-47F9-BCBB-A04C615BA4BE}

尝试从某个列表的列表设置页面获取列表查询参数,以确保您拥有正确的 GUID(有时对卷曲的 GUID 很挑剔)大括号也)。

The ListViewWebPart expects a GUID, and you're giving it a three digit number. Are you trying to pass in the item ID? A list ID will look something like this: {880B8CC4-A1C4-47F9-BCBB-A04C615BA4BE}

Try grabbing the List query parameter from the list settings page of some list to ensure that you have the proper GUID (sometimes it's picky about having the curly braces too).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文