Application pages for dummies. Part 2.

by | Oct 26, 2012 | Development, SharePoint | 3 comments

Finally, I was able to finish the second part of the post about SharePoint 2010 application pages. First part can be found here. At the end of the previous post you saw that for the new item we need a page for it. In my case, it’s “WorkFlow01_New.aspx”. Of course, we can imagine that the same form will be used for all tasks, but it could be to complicated and messy. Anyway, we add a new application page to the project and then we place it into “PlaceHolderMain” module following controls: 5 labels, 4 text fields, 1 calendar control, and a button. The tricky part is that we don’t have access to the graphic designer of VSTO, so we can’t see our design of the page in the fly. See below my simple page. As you can see there’s nothing fancy.

<asp:ContentID=”PageHead”ContentPlaceHolderID=”PlaceHolderAdditionalPageHead”runat=”server”>

</asp:Content>

 

<asp:ContentID=”Main”ContentPlaceHolderID=”PlaceHolderMain”runat=”server”>

<tablewidth=”1000″>

<tr>

<td><asp:LabelID=”LbInvoiceNumber”runat=”server” Text=”InvoiceNumber”> </asp:Label></td>

<td><asp:LabelID=”LbInvoiceDate”runat=”server”Text=”InvoiceDate”>

</asp:Label></td>

<td><asp:LabelID=”LbInvoiceAmount”runat=”server”Text=”InvoiceAmount”>

</asp:Label></td>

<td><asp:LabelID=”LbSupplier”runat=”server”Text=”Supplier”>

</asp:Label></td>

<td><asp:LabelID=”LbPurchaseOrder”runat=”server”Text=”PurchaseOrder”>

</asp:Label></td>

</tr>

  

<tr>

    <td><asp:TextBoxID=”InvoiceNumber”runat=”server”></asp:TextBox></td>

    <td><asp:CalendarID=”InvoiceDate”runat=”server”></asp:Calendar></td>

    <td><asp:TextBoxID=”InvoiceAmount”runat=”server”></asp:TextBox></td>

    <td><asp:TextBoxID=”Supplier”runat=”server”></asp:TextBox></td>

    <td><asp:TextBoxID=”PurchaseOrder”runat=”server”></asp:TextBox></td>

</tr>

</table>

<asp:ButtonID=”SaveToList”runat=”server”Text=”Save to list”OnClick=”SaveList”on/>

 

</asp:Content>

 

<asp:ContentID=”PageTitle”ContentPlaceHolderID=”PlaceHolderPageTitle”runat=”server”>

Application Page

</asp:Content>

 

<asp:ContentID=”PageTitleInTitleArea”ContentPlaceHolderID=”PlaceHolderPageTitleInTitleArea”runat=”server”>

My Application Page

</asp:Content>

image

Now it’s time to create a method to send data to the list. When you use the application page all behaviors depend on you, so without that the button will be useless. As you see in the code of the page, I put already OnClick method into button control. The method code is below:

protectedvoid SaveList(object sender, EventArgs e)

        {

        

            SPList list = SPContext.Current.Web.Lists.TryGetList(“Financial Workflow List”);

           

            SPListItem newItem = list.Items.Add();

            newItem[“InvoiceNr”]=InvoiceNumber.Text.ToString() ;

            newItem[“InvoiceDt”]=InvoiceDate.SelectedDate ;

            newItem[“InvoiceAm” ]=InvoiceAmount.Text ;

            newItem[“Supplier” ]=Supplier.Text.ToString ();

            newItem[“PurchaseOrder”]=PurchaseOrder.Text.ToString()  ;

            newItem.Update();

         

            HttpContext context = HttpContext.Current;

               if (HttpContext.Current.Request.QueryString[“IsDlg”] != null)

                {

                    context.Response.Write(“<script type=’text/javascript’>window.frameElement.commitPopup()</script>”);

                       context.Response.Flush();

                       context.Response.End();

                       }              

                }

    }

Ok, so what do we do? The first part of the code creates an instance of our list. Then we assign values of our controls to proper columns of the list. And after that, we finally call Update() method to put data on the list. In the end, we have to remove the application page from the screen. Also this last part of the code refresh content of our list.

And that’s all. I’ll try to create the next part of the series “Application pages” and present how we can place there additional functionality.

Written by Tomasz Szulczewski

Hi, my name is Tomasz Szulczewski, and I have been in love with information technology for over 25 years, but I still have an IT passion and feel like a geek. I am a person who is problem solver who thinks that not all people must be experts in IT.

Related Posts

What is SharePoint in Office 365?

What is SharePoint in Office 365?

What is SharePoint in Office 365, and why is SharePoint for small business the critical product? So you bought a Microsoft 365 license, and your tenant is online. You open a browser, and you have no idea what to do next? Don't worry; I will try to give you a few...

read more
Hubfly

Hubfly

A few days ago I have a chance to play with SharePoint online solution called Hubfly and I was really impressed with his capabilities. And here is my review. So let’s start from the begging. I wrote a few times on this blog that the main problem with SharePoint is...

read more

3 Comments

  1. Raheena

    nice article.. waiting for you to post part 3.

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.