sharepoint 2010 弹出形式窗口showModalDialog并返回值returnResult方法

sharepoint 2010 弹出模式窗口showModalDialog并返回值returnResult方法

1。创建一个BasePage.aspx页面。

 <asp:Content ID="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>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<input type="text" id="ItemID"  runat="server" />
    <input id="BtnOpen" type="button" value="选择" onclick="showDialog()"  />
</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
应用程序页
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
我的应用程序页
</asp:Content>

2。创建一个弹出页面。ShowDialogPage.aspx

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<script>

    //返回值方法
    function ReturnPageValue()
    {
        window.frameElement.commitPopup(document.getElementById('<%=txtValue.ClientID %>').value);
    }
</script>
</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <input id="txtValue" type="text" runat="server"  />
    <input id="BtnOK" type="button" value="确定" onclick="ReturnPageValue();" />
    <input id="BtnClose" type="button" value="关闭" onclick="window.frameElement.cancelPopUp();" />
</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
应用程序页
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
我的应用程序页
</asp:Content>

3。部署到MOSS环境。

点击选择按钮

sharepoint 2010 弹出形式窗口showModalDialog并返回值returnResult方法

弹出ShowDialogPage.aspx页面

sharepoint 2010 弹出形式窗口showModalDialog并返回值returnResult方法

 在文本框填写“我是返回值”,点击确定。如下图,“我是返回值”,已经返回到文本框。

 sharepoint 2010 弹出形式窗口showModalDialog并返回值returnResult方法

程序下载地址:http://download.csdn.net/detail/cxx2325938/5162960

广州京微信息科技有限公司,微软sharepoint解决方案提供商。