There are two approaches we can follow while creating an Application Page in SharePoint.
One is Inline Approach
· Create a new default.aspx page rename it to HelloWorldAppPage.aspx
· Put the following markup in it
<%@ Page Language=”C#” MasterPageFile=”~/_layouts/application.master” Inherits=”Microsoft.SharePoint.WebControls.LayoutsPageBase” %>
<asp:Content ID=”Main” ContentPlaceHolderID=”PlaceHolderMain” runat=”server”>
<asp:Label Text=”Hello World” runat=”server” ></asp:Label>
</asp:Content>
· Every application page is an content page in SharePoint. And here to have same look and feel as the other application pages we have specified the application.master as the masterpagefile.
· Inherits attribute of the Page directive refers to LayoutsPageBase class from which the application pages inherit.
· We have than used a content server control that would be referring to the PlaceHolderMain content place holder inside the application.master page.
· Than we have simple added a label control that would be displaying hello world.
· Now go to your 12 hive i.e. C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTS and create a folder (MyHelloWorld) over there and put the HelloWorldAppPage.aspx over there.
· We could have directly placed the aspx page to layouts folder but than from better organization perspective we have created a folder and kept the aspx page inside it.
· Now the page is available to all the SharePoint sites.
http://servername:port/_layouts/MyHelloWorld/HelloWorldAppPage.aspx
Another is code behind approach.
· The easiest way is to first create a Asp.NET Web site project.
· Add a class library project to the solution (GCL)
· Delete class1.cs and copy the default.aspx.cs page from asp.net web site project to the class library project.
· Delete the default.aspx.cs from the website.
· Add reference to System.Web and Microsoft.SharePoint.dll in your class library project
· Put the following code in the _Default
public partial class _Default : LayoutsPageBase
{
protected Label Label1;
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = “Hello World Code Behind”;
}
}
· Sign the assembly and put it in GAC.
· Get the public key token.
· In the default.aspx page replace and put the following markup to use the assembly.
<%@ Page Language=”C#” MasterPageFile=”~/_layouts/application.master”
Inherits=”_Default,GCL, Version=1.0.0.0,Culture=neutral,PublicKeyToken=16391a8a7c882343″ %>
<asp:Content ID=”Main” ContentPlaceHolderID=”PlaceHolderMain” runat=”server”>
<asp:Label ID=”Label1″ Text=”Hello World” runat=”server” ></asp:Label>
</asp:Content>
· Put default.aspx to the layouts folder or your custom folder inside it.
That’ s it !!
RSS - Posts

[...] Create a simple hello world custom Application Page in SharePoint. [...]
By: Links (2/26/2009) « Steve Pietrek - Everything SharePoint on February 27, 2009
at 12:42 am
You may also want to take a look at the other approaches to surface up code in SharePoint:
http://www.sharepointdevwiki.com/display/public/Approaches+to+integrate+ASP.NET+web+application+into+SharePoint
By: Jeremy Thake on February 27, 2009
at 1:20 am
This is a nice post.
Though I’m wondering how to get a button to work, because when I use a button, I also need an event handler for that button, when it’s clicked. So I am wondering how that would work.
I did:
protected Button Button1;
protected override void OnLoad(EventArgs e)
{
Button1 = new Button();
Button1.Text = “Click”;
Button1.Click += new EventHandler(Button1_Click);
}
void Button1_Click(object sender, EventArgs e)
{
//code
}
and in my aspx page:
I added a button with name “Button1″ and tried to put a OnClick attribute, but that didn’t work, I got a “Method not found” error. When i remove that, the page is displayed, but the button only performs a postback.
By: Johan Beerden on March 23, 2009
at 3:36 pm
This is a nice post.
I am having the same problem Johan reported. I have added a button to the page and added an event handler. The button will post the page but does not raise the event as expected.
Is there a trick to getting control events to work?
By: Richard Carroll on March 29, 2009
at 5:17 pm
Hi Richard,
You will not have the issue when you code it inline. That’s the solution Nishant sent me.
But ofcourse I would like to have a solution to do it all in code behind. And i succeeded.
Actually it’s quiet simple to do (and a stupid error too).
Just leave the instantiation of the controls you’ve placed on your aspx page out and it will work.
Why? The controls are already instantiated. And because you inherit from the code behind, the declaration “protected Button button1″ points to the same place in memory as the button1 on your aspx form.
So my correct code would be:
protected Button Button1;
protected override void OnLoad(EventArgs e)
{
Button1.Text = “Click”;
Button1.Click += new EventHandler(Button1_Click);
}
protected void Button1_Click(object sender, EventArgs e)
{
//code
}
protected is necessary because private (standard when only void is used) wouldn’t be accessible by your aspx.
Hope this helps.
By: Johan Beerden on March 30, 2009
at 7:04 am
Is not spam, it is only my commercial offer. Sorry if i mistake of topic!
Buy Clomid – Best testimonials. Buy now. Satisfaction is guaranteed.
Best price for brand and generic medications.
From $0.60 per item. Free Airmail shipping for Clomid 100mg 90 tabs and save $135 on order!
By: buyclomido on August 30, 2009
at 9:58 am
[...] http://nishantrana.wordpress.com/2009/02/26/create-a-simple-hello-world-custom-application-page-in-s... Possibly related posts: (automatically generated)meta-se wordpress için SEO eklentisiwriting, writing, and more writing (just not here.) Leave a Comment [...]
By: Sharepoint Custom Application Page « Sladescross's Blog on October 6, 2009
at 9:00 pm