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 !!
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
LikeLike
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.
LikeLike
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?
LikeLike
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.
LikeLike
Would you please post your .aspx? It seams im missing something
LikeLike
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”
LikeLike
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!
LikeLike
/**************************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
LikeLike
i followed the code behind – approach that time
i am getting error like ‘Your are not authorised person to view page ‘
LikeLike
Thank you so much. Link was really helpful. Do you know how can i add custom themes to .aspx page?
LikeLike
Имеется большое количество сайтов, где без труда вы имеете возможность закачать или просмотреть ролики. Аэнтар с сожалением отключил Палантир и поплелся за Элхэ, натыкаясь на стены и не вписываясь в повороты. . Есть альтернатива – это ТВ онлайн.
LikeLike
Hi,
can you please tell me how to create a document library with the tree view control.
LikeLike
fsfsfsfsfs
LikeLike
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
LikeLike
Hey guys,
I am getting the error.
Could not load the assembly ‘Version=1.0.0.0, Culture=neutral, PublicKeyToken=553dbbf1b9a1f6ba’. Make sure that it is compiled before accessing the page. at System.Web.UI.TemplateParser.GetType(String typeName, Boolean ignoreCase, Boolean throwOnError)
please help
LikeLike
This founded on the fact that the urethra (tube in penis employed as passage for urine and semen) can absorb certain medicines for the surrounding tissues and causes creating erection. She must extend all his support and goodwill and strive to learn everything concerning the issue. Acupuncture can correct erectile dysfunction.
LikeLike
The injectible used are Progtaglanden (PGEI-or Prostin or Alpostradil or Caverject) papaverine hydrochloride and phentolamine (Regitine). They really should both other venues for reaching their mutual sexual satisfaction. An impotent males’ way of living must be changed for the better. There will also be a laboratory and some other tests.
LikeLike
When oral medications fail, intravenous therapy could be accomplished as an alternative where the drug is injected directly to the penis. Other options for a man to sustain an erection are:utilizing a Vacuum Constriction Device (VCD), Intraurethal therapy or Penile Implant. Parkinson Illness is really a risk factor for potency and most of the time is over-looked.
LikeLike
Erectile dysfunction is worldwide and affects hundreds of thousands of men irrespective of the race and region. Fortunately, we have a lot of cures for erectile dysfunction. Let us look at some of the essential cures for erectile dysfunction .
LikeLike
Age Most males can have strong erections until they are about 80 years old. Nevertheless, 80 percent of men who’re over the age of 75 tend to have erectile dysfunction. Know that whilst this sounds like age will be the culprit, normally older men are having erectile dysfunctions because of other medical issues they’ve developed with age (high blood pressure, heart issues, and so on.
LikeLike
Erectile dysfunction is also known as impotence and in this difficulty erection just isn’t so difficult to do sexual intercourse and second factor males can not keep erection as long that he can finish the intercourse properly. This erection dysfunction problem effects lots of males and there sexual life. The major reason of erectile dysfunction is deficiency of testosterone simply because because of testosterone erection occurs
LikeLike
Erectile dysfunction may cause or exacerbate psychological troubles for example poor motivation, feelings of inadequacy, frustration, denial and low self-esteem, and could ultimately result in depression. Erectile dysfunction includes multiple sexual disorders, but most frequently it’s regarded as to be the persistent inability to have an erection or to maintain it for a sufficient amount of time. Erectile dysfunction (ED), also recognized as impotence, will be the inability to achieve or sustain an erection for satisfactory sexual activity.
LikeLike
It is a real wake-up call for males with both erectile dysfunction and diabetes, says Allen Seftel, a urologist at Case Western University. In light of the new findings, he says, diabetics who develop ED need to be specially prompt about searching for medical attention and finding tested for cardiovascular disease.
LikeLike
Those looking for erectile dysfunction drugs normally try Viagra initial because it’s known to be powerful. Cialis, on the other hand, is also most sought by those looking for powerful erectile dysfunction drugs due to the fact it stays longer in the body 24 to 36 hours compared to the other two.
LikeLike
When it is all about sexual pleasure, there’s no compromise either for a woman or for a man. Unfortunately, man suffers more than woman about sexual dysfunction given that there are numerous chances that male reproductive method and its organs to get affected due to plenty of elements. Erectile dysfunction is among the significant concerns that have hit millions of males across the globe; irrespective of the race, breed and region.
LikeLike
Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point.
You definitely know what youre talking about, why throw away your intelligence on just posting videos to your site when you could
be giving us something enlightening to read?
LikeLike
Du musst einige online-Forschung zu tun, um eine gute und echte online-Shop zu finden. Sie können auch sprechen, Familie oder Freunde, die Erfahrung in der Medizin in einem Onlineshop zu kaufen.
LikeLike
ohCaep9g
LikeLike