Creating Empty SharePoint Project:
- Open Visual Studio 2010.
- Go to File => New => Project.
- Select 2010 from the installed templates SharePoint and choose Empty SharePoint Project.
- Name it as CustomApplicationPage.
- Click Add.
- Enter the SharePoint server farm URL.
- Select ‘Deploy it as a Farm Solution”.
- Click Finish.
Adding Application Page:
- Right click the Solution Explorer and select Add a new item.
- Select Application Page from the installed templates SharePoint and name it as CustomApplicationPage.
- Once you add the application page it will automatically create the Layouts Folder.
- In the solution explorer you could see Layouts -> CustomApplicationPage ->CustomApplicationPage.aspx.
- Once you deploy the solution the pages will be automatically placed in the 14 hive layouts folder.
- Open CustomApplicationPage.aspx from the solution explorer.
- In the “PlaceHolderMain” add one asp label control.
- And change the “PlaceHolderPageTitle” content to ‘My Application Page” as shown in the following code.ASPX Code
<%@ Assembly Name=”$SharePoint.Project.AssemblyFullName$” %>
<%@ Import Namespace=”Microsoft.SharePoint.ApplicationPages” %>
<%@ Register TagPrefix=”SharePoint” Namespace=”Microsoft.SharePoint.WebControls”
Assembly=”Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register TagPrefix=”Utilities” Namespace=”Microsoft.SharePoint.Utilities” Assembly=”Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register TagPrefix=”asp” Namespace=”System.Web.UI” Assembly=”System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ %>
<%@ Import Namespace=”Microsoft.SharePoint” %>
<%@ Assembly Name=”Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %><%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”MyApplicationPage.aspx.cs”
Inherits=”spFarmCS.Layouts.spFarmCS.CustomApplicationPage” DynamicMasterPageFile=”~masterurl/default.master” %><asp:Content ID=”PageHead” ContentPlaceHolderID=”PlaceHolderAdditionalPageHead” runat=”server”>
My Page Head
</asp:Content>
<asp:Content ID=”Main” ContentPlaceHolderID=”PlaceHolderMain” runat=”server”>
<table><tr><td><asp:UpdatePanel ID=”upMyUpdatePanel” runat=”server” UpdateMode=”Always”>
<ContentTemplate><table><tr><td colspan=”2″>
<h1>Select the state</h1></td></tr>
<tr><td>State</td><td>
<asp:DropDownList ID=”ddlState” runat=”server” OnSelectedIndexChanged=”ddlState_SelectedIndexChanged”
AutoPostBack=”true”>
<asp:ListItem Text=”–select–” Value=”-1″ /><asp:ListItem Text=”Maharashtra” Value=”1″ />
<asp:ListItem Text=”Gujarat” Value=”2″ /><asp:ListItem Text=”Karnataka” Value=”3″ />
</asp:DropDownList>
</td></tr><tr><td>City</td>
<td><asp:DropDownList ID=”ddlCity” runat=”server”></asp:DropDownList></td>
</tr></table>
</ContentTemplate></asp:UpdatePanel>
</td>
</tr>
</table>
</asp:Content>
<asp:Content ID=”PageTitle” ContentPlaceHolderID=”PlaceHolderPageTitle” runat=”server”>
Sharepoint Application Page
</asp:Content>
<asp:Content ID=”PageTitleInTitleArea” ContentPlaceHolderID=”PlaceHolderPageTitleInTitleArea”
runat=”server”>
Using Application Page in Share Point
</asp:Content>CS Codeusing System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;namespace spFarmCS.Layouts.spFarmCS
{
public partial class MyApplicationPage : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCity.Items.Clear();if (ddlState.SelectedItem.Text == “Maharashtra”)
{
ddlCity.Items.Add(new System.Web.UI.WebControls.ListItem(“–select–“, “-1″));
ddlCity.Items.Add(new System.Web.UI.WebControls.ListItem(“Mumbai”, “1”));
ddlCity.Items.Add(new System.Web.UI.WebControls.ListItem(“Pune”, “2”));
}
else if (ddlState.SelectedItem.Text == “Gujarat”)
{
ddlCity.Items.Add(new System.Web.UI.WebControls.ListItem(“–select–“, “-1″));
ddlCity.Items.Add(new System.Web.UI.WebControls.ListItem(“Rajkot”, “1”));
ddlCity.Items.Add(new System.Web.UI.WebControls.ListItem(“Ahmdabad”, “2”));
}
else if (ddlState.SelectedItem.Text == “Karnataka”)
{
ddlCity.Items.Add(new System.Web.UI.WebControls.ListItem(“–select–“, “-1″));
ddlCity.Items.Add(new System.Web.UI.WebControls.ListItem(“Banglore”, “1”));
ddlCity.Items.Add(new System.Web.UI.WebControls.ListItem(“Mysore”, “2”));
}
}
}
} - Build the solution.
- Deploy the solution.
Testing:
- Go to the http://servername:2010/_layouts/CustomApplicationPage/ CustomApplicationPage.aspx.
- A new custom application page has been created in SharePoint 2010 as shown below.
Summary:
This article is mainly written to explain that a new template “Application Page” is available in the installed templates “SharePoint ” -> “2010” and how to use that in visual studio 2010
No comments:
Post a Comment