Editar o agregar listItem a la lista en ApplicationPage con ListFormWebPart o DataFormWebPart, pero ¿cómo?

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/19617

Pregunta

Quiero hacer esta base programada en ListID y listItemid (para editar), así que, si quiero usar DataFormwebPart, tengo que configurar la propiedad XSL en modo de diseño y no sé cómo llegar al XSL de la lista de destino en tiempo de ejecución y objeto modelo. Puedo cambiar la lista de destino en la cadena de consulta, pero la interfaz no va a cambiar porque la propiedad XSL no está definida:

    <WebPartPages:DataFormWebPart id="dataForm" runat="server" IsIncluded="True" NoDefaultStyle="TRUE" 
    ViewFlag="8" Title="TestParnian" PageType="PAGE_EDITFORM" ListName="{8965AE3A-CCA0-4502-B7CE-056CD670C016}" Default="FALSE" 
    DisplayName="TestParnian" __markuptype="vsattributemarkup" __WebPartId="{2CDB3F60-D76F-4410-AEDA-28D9D5815854}">
    <DataSources>
        <SharePoint:SPDataSource id="TestParnian2" runat="server" DataSourceMode="ListItem" UseInternalName="true" 
            UseServerDataFormat="True" 
            selectcommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;ContentType&quot;/&gt;&lt;Value Type=&quot;Text&quot;&gt;مورد&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;">
        <SelectParameters>
            <WebPartPages:DataFormParameter Name="ListItemId" ParameterKey="ListItemId" 
                PropertyName="ParameterValues" DefaultValue="0"/>
            <WebPartPages:DataFormParameter Name="ListID" 
                ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{8965AE3A-CCA0-4502-B7CE-056CD670C016}"/>
            <WebPartPages:DataFormParameter Name="MaximumRows" ParameterKey="MaximumRows" PropertyName="ParameterValues" 
                DefaultValue="10"/>
        </SelectParameters>
        <InsertParameters>
            <WebPartPages:DataFormParameter Name="ListItemId" ParameterKey="ListItemId" 
                PropertyName="ParameterValues" DefaultValue="0"/>
            <WebPartPages:DataFormParameter Name="ListID" 
                ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{8965AE3A-CCA0-4502-B7CE-056CD670C016}"/>
        </InsertParameters>
        <UpdateParameters>
            <WebPartPages:DataFormParameter Name="ListItemId" ParameterKey="ListItemId" 
                PropertyName="ParameterValues" DefaultValue="0"/>
            <WebPartPages:DataFormParameter Name="ListID" 
                ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{8965AE3A-CCA0-4502-B7CE-056CD670C016}"/>
        </UpdateParameters>
        </SharePoint:SPDataSource>
    </DataSources>

    <ParameterBindings>
            <ParameterBinding Name="ListItemId" Location="QueryString(ID)" DefaultValue="0"/>
            <ParameterBinding Name="ListID" Location="QueryString(ListID)" DefaultValue="{8965AE3A-CCA0-4502-B7CE-056CD670C016}"/>
            <ParameterBinding Name="MaximumRows" Location="None" DefaultValue="10"/>
            <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
            <ParameterBinding Name="ManualRefresh" Location="WPProperty[ManualRefresh]"/>
            <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
            <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
    </ParameterBindings>
        <XSL> The XSL Property that needs to be define. </XSL>
</WebPartPages:DataFormWebPart>

Por lo tanto, DataFormWebPart no me ayudará. La siguiente opción es ListFormWebPart que no necesita la propiedad XSL y se puede crear en tiempo de ejecución con el modelo de objeto como este:

  int itemId = listItem != null ? int.Parse(listItem.ID.ToString()) : -1;
  ListFormWebPart lstFormList = new ListFormWebPart();

  lstFormList.ListName = lst.ID.ToString("B").ToUpper();
  if (itemId != -1)
  {
     lstFormList.ListItemId = itemId;
     lstFormList.PageType = PAGETYPE.PAGE_EDITFORM;
     lstFormList.ControlMode = SPControlMode.Edit;
     lstFormList.TemplateName = "ListForm";
     lstFormList.FormType = 6;
     lstFormList.Title = "Edit " + lst.Title;
  }
  else
  {
     lstFormList.ControlMode = SPControlMode.New;
     lstFormList.PageType = PAGETYPE.PAGE_NEWFORM;
     lstFormList.TemplateName = "ListForm";
     lstFormList.FormType = 8;
     lstFormList.Title = "Add " + lst.Title;
  }
  lstFormList.ListTitle = lst.Title;
  lstFormList.AllowClose = false;
  lstFormList.AllowConnect = false;
  lstFormList.AllowEdit = false;
  lstFormList.AllowZoneChange = true;
  lstFormList.EnableViewState = true;
  lstFormList.HideIfNoPermissions = true;

  Panel1.Controls.Add(lstFormList);

Este código funciona bien en WebPart pero no en ApplicationPage y debo decir que agregué todos los espacios de nombres y referencias que este WebPart necesita, a la página.
Esto me da este error:

System.NullReferenceException: Referencia de objeto no establecido en una instancia de un objeto. en microsoft.sharepoint.webpartPages.listformwebpart.onperender (EventArgs e) en System.web.ui.Control.PerendErReCursiveInternal () en System.Web.ui.Control.PreerenderReCursiveInternal () en System.Web.ui.Control.PreerenderRecursiveSinternal () () () en System.Web.Ui.Control.PreerendErReCursiveInternal () en System.Web.ui.Control.PreerendRecursiveInternal () en System.Web.ui.Control.PreerEnderRecursiveInternal () en System.Web.ui.Control.PerenderriveResiveinternal () en System .Web.UI.Control.PreerendRecursiveInternal () en System.Web.Ui.Page.ProcessRequestMain (Boolean incluye BeforEsyncpoint, boolean incluye aFterasyncPoint)

Pongo y pruebo este código en Page_Init, Page_Load y ListFormWebPart_Init eventos pero no ningún éxito. Utilizo el diseñador de SharePoint y creo ListFormWebPart y luego cópielo y pegado a la página de mi aplicación y también agregue el ensamblaje necesario para ello, pero tampoco tiene éxito.
No sé cuál es el problema, por favor dale el enfoque correcto si el mío no lo es.

¿Fue útil?

Solución

En primer lugar, OOTB WebParts no es compatible oficialmente para trabajar en páginas de aplicaciones en SharePoint. Como me dijeron, se podía aprender del curso oficial de MS 10232.

Y a pesar de que las partes web en las páginas de aplicaciones en realidad funcionarán en algunos casos, hay muchos problemas potenciales con ellas. Por ejemplo, si proporciona XSllink a un OOTB XSLT-Webpart, como DFWP, DVWP o XLV, intentará almacenarlo en caché y eventualmente fallará con excepción 'intentó usar un objeto que ha dejado de existir'. Además, las personas a menudo tienen problemas con la funcionalidad de cinta WebParts estándar en las páginas de aplicaciones, cuando algunos botones están atenuados.

Entonces, incluso si resuelve su problema hoy, probablemente obtendrá una pareja mañana.

Entonces, básicamente, le recomendaría que cree una página del sitio y coloque su funcionalidad de Parte web deseada allí. Y si necesita algunas acciones programáticas adicionales, puede colocar su PARTE WEBS personalizada en la misma página y realizar todo lo que necesite.

Licenciado bajo: CC-BY-SA con atribución
scroll top