Tuesday, January 29, 2013

Create Simple Application page in SharePoint 2013


Before create the application page in SharePoint you should know general idea about what is Application page? and How it differs from master page and web part? (See here for more details)

      Steps :
      
   01.  Open Visual Studio 2012 
   02.  Create New Project , select SharePoint 2013 project. then type the Name and click "OK".
      
   03. Select “Deploy as Farm Solution” and Select the site for debugging. it should be your    local host.
      
      
   04. Check whether your site is working or not by clicking "Validate" . if it is successful , click "Finish".
           

 
   05. Add New Item (Right click on the Project , Add >> New Item>> Office/SharePoint >>Application Page(Farm Solutions only))

   06. Type the Application Page Name (ApplicationPage1.aspx) and click “Add”.

   07. Once it creates the project, check the site URL and Startup item (Right click on the project file , and click properties). 

       

  • Startup Item will create automatically if you double click the empty box. If you have more than one application page, you have to select the start-up item.
  • There are two ways to edit the page. One is edit the Page Markup and second one is edit the Page code (You can open the View Code , or View Markup to edit if you right click on the applicationpage1.aspx  file)
  • Edit the Page Markup. Put the controls (Button, List box, Radio button…etc.) between the main content tag. You can drag & drop the controls from the toolbox. You can’t view the page until you deploy into SharePoint farm.
  • Once you edit the page markup, you can edit the page code according to your Business logic.


08. Finally build the project and deploy the solution and check the "Output"window for deployment status whether it succeed or failed.

09. Once the deployment is succeed , you can check the page (check the UI & functionality)
  • If you want to check the page after deployed, you have to go to that URL. Or else if you click RUN Button on Visual studio it will automatically open the URL. After that you can use that URL for open the page.
10. If you want to debug the code, attach the processes (w3wp.exe) with visual studio project after deploy before open the page. (Debug >> Attached to Processes >> select all w3wp.exe and click attach). Then open the page , it will automatically stop at first break point



Be careful
  • Since all the controls are ASP.Net, every time it will send the request to server, so every time it will reload the page. Design your code according to this.
  • If you want, you can use “IsPostBack”  method to identify the first page load . 
        - First time page load/ refresh the page/ reload the page - - - > IsPostBack = = true
        - Page load by clicking the buttons - - - > IsPostBack = false Or else you can use session variables