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 !!


This is one of the best articles so far I have read online. No crap, just useful information. Very well presented. Thanks for sharing with us. Check out this link too its also having a wonderful explanation on how to use custom application page in sharepoint…
http://mindstick.com/Articles/6345ba2f-1a8b-4ccf-9c81-d656ea0b4bf2/?Custom%20Application%20Page%20in%20SharePoint
Thanks
fsfsfsfsfs
Hi,
can you please tell me how to create a document library with the tree view control.
Имеется большое количество сайтов, где без труда вы имеете возможность закачать или просмотреть ролики. Аэнтар с сожалением отключил Палантир и поплелся за Элхэ, натыкаясь на стены и не вписываясь в повороты. . Есть альтернатива – это ТВ онлайн.
Thank you so much. Link was really helpful. Do you know how can i add custom themes to .aspx page?
i followed the code behind – approach that time
i am getting error like ‘Your are not authorised person to view page ‘
/**************************example******
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = “Hello World Code Behind”;
}
protected void btnSubmit_onclick(object sender, EventArgs e)
{
Label1.Text = “Hiiii…”;
this.txtValue.Text = “click submit”;
}
Testing custom application page
http://sys-97/testdorlog/_layouts/samarendra/Test.aspx
/**************************end******
It’s working fine for me……
Thanks
-Samarendra Swain
[...] 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 [...]
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!
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.
Would you please post your .aspx? It seams im missing something
I figure it out my problem…. I needed to add AutoEventWireup=”true” on the aspx
and wire the event as follows:
in the code behind create method “resetPassBtn_Click”
so the key was the AutoEventWireup=”true”
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?
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.
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
[...] Create a simple hello world custom Application Page in SharePoint. [...]