1。创建一个BasePage.aspx页面。
<asp:ContentID="PageHead"
ContentPlaceHolderID="PlaceHolderAdditionalPageHead"
runat="server">
<script>
function showDialog() {
var options = {
url: "ShowDialogPage.aspx",
args: 7,
title: "选择页面",
dialogReturnValueCallback: dialogCallback
};
SP.UI.ModalDialog.showModalDialog(options);
}
//接收返回值方法
function dialogCallback(dialogResult, returnValue) {
//其中dialogResult=1,代表确定,dialogResult=0,代表关闭
if (returnValue !=
null && dialogResult == 1) {
alert(returnValue); //弹出窗口
document.getElementById('<%=ItemID.ClientID%>').value = returnValue;
}
return;
}
</script>
</asp:Content>
2。创建一个弹出页面。ShowDialogPage.aspx
<asp:ContentID="PageHead"
ContentPlaceHolderID="PlaceHolderAdditionalPageHead"
runat="server">
<script>
//返回值方法
function ReturnPageValue() {
window.frameElement.commitPopup(document.getElementById('<%=txtValue.ClientID%>').value);
}
</script>
</asp:Content>
<asp:ContentID="Main"
ContentPlaceHolderID="PlaceHolderMain"
runat="server">
<inputid="txtValue"
type="text"
runat="server" />
<inputid="BtnOK"
type="button"
value="确定"onclick="ReturnPageValue();"/>
<inputid="BtnClose"
type="button"
value="关闭"onclick="window.frameElement.cancelPopUp();"/>
</asp:Content>
<asp:ContentID="PageTitle"
ContentPlaceHolderID="PlaceHolderPageTitle"
runat="server">
应用程序页
</asp:Content>
<asp:ContentID="PageTitleInTitleArea"
ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
runat="server"
>
我的应用程序页
</asp:Content>
3。部署到MOSS环境。
点击选择按钮
弹出ShowDialogPage.aspx页面。
在文本框填写“我是返回值”,点击确定。如下图,“我是返回值”,已经返回到文本框。