In this
example I will show you how to open application page as a pop up using java
script. It is very commonly and most important requirement in SharePoint 2010
development.
Here is an example, say I have an application page called
applicationpage1.aspx and code
behind is - applicationpage1.aspx.cs.
And want to open the application page as pop up on click of hyperlink.
Write a java script code in applicationpage1.aspx as follows, in this example, I am passing
only one parameter.
Briefly
Parent
page - The java script code in .aspx page
<script type="text/javascript">
function EditDoc(itemID)
{
var options
= {
// path of the document to be opened as pop up. Replace ‘xxxxxx’
with you actual page.
url: "/_layouts/XXXXXXXX/EditDocument.aspx?ID="
+ itemID, allowMaximize: true, showClose: true, height: 300,
dialogReturnValueCallback: function (result, returnValue) {
window.location.href = window.location.href;
}
};
modalDialog
= SP.UI.ModalDialog.showModalDialog(options);
}
</script>
Parent
page – The item databound of the Telerik grid or data grid in code behind page
(dataItem["EditDoc"].FindControl("EditDocument") as
HyperLink).NavigateUrl = string.Format("javascript:EditDoc({0});",
dataItem["ID"].Text);
In child page (opened as pop up) auto refresh back to
parent page
After you logic, at the end use following code
Context.Response.Write(string.Format("<script
type='text/javascript'>window.frameElement.commitPopup();</script>"));
Context.Response.Flush();
Context.Response.End();
In
detail
<asp:Content ID="PageHead"
ContentPlaceHolderID="PlaceHolderAdditionalPageHead"
runat="server">
<script type="text/javascript"
src="/_layouts/<%=System.Threading.Thread.CurrentThread.CurrentUICulture.LCID%>/init.js"></script>
<script type="text/javascript"
src="/_layouts/<%=System.Threading.Thread.CurrentThread.CurrentUICulture.LCID%>/core.js"></script>
<script type="text/javascript">
function
EditDoc(itemID) {
var options = {
//
path of the document to be opened as pop up. Replace ‘xxxxxx’ with you actual
page.
url:
"/_layouts/XXXXXXXX/EditDocument.aspx?ID=" + itemID, allowMaximize:
true, showClose: true, height: 300, dialogReturnValueCallback: function
(result, returnValue) {
window.location.href =
window.location.href;
}
};
modalDialog = SP.UI.ModalDialog.showModalDialog(options);
}
</script>
</asp:Content>
<asp:Content ID="Main"
ContentPlaceHolderID="PlaceHolderMain" runat="server">
<telerik:RadGrid
ID="RadGrid1" AllowPaging="false" runat="server"
AllowSorting="true"
AutoGenerateColumns="false"
AllowFilteringByColumn="false" HeaderStyle-Font-Bold="true"
OnNeedDataSource="RadGrid1_NeedDataSource"
OnItemDataBound="RadGrid1_ItemDataBound" GridLines="None"
OnItemCommand="RadGrid1_ItemCommand"
CssClass="OverrideTelerikGridStyles">
<ClientSettings
EnableAlternatingItems="false"></ClientSettings>
<MasterTableView
GroupLoadMode="Client" TableLayout="Fixed" GroupsDefaultExpanded="true">
<Columns>
<telerik:GridTemplateColumn
ItemStyle-Width="110px" UniqueName="EditDoc"
AllowFiltering="false" ItemStyle-ForeColor="Blue"
ItemStyle-Font-Underline="true">
<ItemTemplate>
<asp:HyperLink ID="EditDocument"
runat="server" Text="Edit Docuemnt"></asp:HyperLink>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</asp:Content>
In applicationpage1.aspx.cs
protected void RadGrid1_ItemDataBound(object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
try
{
if
(e.Item is GridDataItem)
{
GridDataItem dataItem =
e.Item as GridDataItem;
(dataItem["EditDoc"].FindControl("EditDocument") as
HyperLink).NavigateUrl = string.Format("javascript:EditDoc({0});",
dataItem["ID"].Text);
}
}
}
Second part… EditDocument.aspx (this is the page opened
as pop up) now once you are done entering some data and want to save and go
back to the parent page. How to go back to parent page without refreshing the
parent page
Say I have two buttons in pop page say OK and Cancel.
Following code in OK button click event
Context.Response.Write(string.Format("<script
type='text/javascript'>window.frameElement.commitPopup();</script>"));
Context.Response.Flush();
Context.Response.End();
Following code in Cancel button click event
Context.Response.Write(string.Format("<script
type='text/javascript'>window.frameElement.commitPopup();</script>"));
Context.Response.Flush();
Context.Response.End();
Happy coding....