none
How can I add Custom WebPart to Application Page or site page in visual studio? RRS feed

  • Question

  • hi all,

    I want add custom webpart to application page in VS,

    1. I create custom webpart

    2. I create Application page

    now I want add the custom webpart to the application page but how ?

    Or if this is BAD IDEA! Is there better way?
    e.g. to add Module and add aspx page and add the webpart to the aspx page?! is this better way?

    if anyone has an idea or advice please tell me.

    thanks in advance
    Ahmad


    SP 2013 & SPD 2013 & VS 2013 & MSSQL 2012


    • Edited by Neeloj Friday, August 8, 2014 2:57 PM change
    Friday, August 8, 2014 2:33 PM

Answers

  • thanks for your answer  Ransher Singh, but that didnt work for me!.

    I added new WEBPART-PAGE to the subsite and than I add my webpart to that WEBPART-PAGE!

    I open that WEBPART-PAGE in SPD and in advanced mode.

    I saw the register which I need and the WEBPART ZONE.

    I take them and added to my APPLICATION-PAGE and works very good.

    Here is the code for all others:

    in the application page this is the register:

    <%@ Register TagPrefix="WpNs0" Namespace="CustomForm.MyWebPartName" Assembly="CustomForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8834df117dc574a9"%>

    and this is in the PlaceHolderMain:

    <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
         <WebPartPages:WebPartZone runat="server" Title="loc:Header" ID="Header" FrameType="TitleBarOnly">
             <ZoneTemplate>
                 <WpNs0:MyWebPartName runat="server" Description="Visuelles Webpart" 
                     ImportErrorMessage="error message" Title="My WebPart" 
                     ID="g_5b3b4e3d_bea5_4def_a793_44cf412c0c9f" __MarkupType="vsattributemarkup" 
                     __WebPartId="{5B3B4E3D-BEA5-4DEF-A793-44CF412C0C9F}" WebPart="true" 
                     __designer:IsClosed="false" partorder="2">
                 </WpNs0:MyWebPartName>
             </ZoneTemplate>
         </WebPartPages:WebPartZone>
    </asp:Content>
    thanks  Ransher Singh again.

    BR
    Ahmad

    SP 2013 & SPD 2013 & VS 2013 & MSSQL 2012

    • Marked as answer by Neeloj Sunday, August 10, 2014 12:18 PM
    Sunday, August 10, 2014 12:11 PM

All replies

  • You are on the right track. You will need to provision the web part within the page /page layout as below

    <%@ Page Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" MasterPageFile="~masterurl/default.master" Language="C#" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document" %>
    <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
    <asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server"></asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" runat="server">     
    <WebPartPages:WebPartZone runat="server" AllowPersonalization="true" ID="WebPartZone2" FrameType="TitleBarOnly" Title="Bottom" Orientation="Vertical">        
    <ZoneTemplate>           
    <WebPartPages:ClientWebPart runat="server"                 FeatureId="17297f8b-5333-46d8-8af6-78e282ea4f22"                 ProductWebId="57278E26-4B76-4AC8-8EFE-C52FB279635E"                 WebPartName="MyWebPart"                 Title="My WebPart Title"                 Description="WebPart Description"                 WebPart="true">                
    <Properties>                    
    <WebPartPages:ClientWebPartProperty Name="myIntProp" Value="7"></WebPartPages:ClientWebPartProperty>                    <WebPartPages:ClientWebPartProperty Name="myEnumProp" Value="EnumValue1"></WebPartPages:ClientWebPartProperty>                </Properties>            
    </WebPartPages:ClientWebPart>        
    </ZoneTemplate>    </WebPartPages:WebPartZone> </asp:Content> 



    Thanks, Ransher Singh, MCP, MCTS | Click Vote As Helpful if you think that post is helpful in responding your question click Mark As Answer, if you think that this is your answer for your question.


    Friday, August 8, 2014 3:56 PM
  • thanks for your answer  Ransher Singh, but that didnt work for me!.

    I added new WEBPART-PAGE to the subsite and than I add my webpart to that WEBPART-PAGE!

    I open that WEBPART-PAGE in SPD and in advanced mode.

    I saw the register which I need and the WEBPART ZONE.

    I take them and added to my APPLICATION-PAGE and works very good.

    Here is the code for all others:

    in the application page this is the register:

    <%@ Register TagPrefix="WpNs0" Namespace="CustomForm.MyWebPartName" Assembly="CustomForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8834df117dc574a9"%>

    and this is in the PlaceHolderMain:

    <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
         <WebPartPages:WebPartZone runat="server" Title="loc:Header" ID="Header" FrameType="TitleBarOnly">
             <ZoneTemplate>
                 <WpNs0:MyWebPartName runat="server" Description="Visuelles Webpart" 
                     ImportErrorMessage="error message" Title="My WebPart" 
                     ID="g_5b3b4e3d_bea5_4def_a793_44cf412c0c9f" __MarkupType="vsattributemarkup" 
                     __WebPartId="{5B3B4E3D-BEA5-4DEF-A793-44CF412C0C9F}" WebPart="true" 
                     __designer:IsClosed="false" partorder="2">
                 </WpNs0:MyWebPartName>
             </ZoneTemplate>
         </WebPartPages:WebPartZone>
    </asp:Content>
    thanks  Ransher Singh again.

    BR
    Ahmad

    SP 2013 & SPD 2013 & VS 2013 & MSSQL 2012

    • Marked as answer by Neeloj Sunday, August 10, 2014 12:18 PM
    Sunday, August 10, 2014 12:11 PM