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

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页面

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

关闭弹出窗口的页面有三种方法可以调用:

1,window.frameElement.cancelPopUp(),调用该方法,将关闭窗口。返回值result是:SP.UI.DialogResult.cancel

2.window.frameElement.commitPopup(),调用该方法,将关闭窗口。返回值result是:SP.UI.DialogResult.ok

3.window.frameElement.commonModalDialogClose(),同上,不过返回值是指定的第一个参数。

下面是传回值的示例代码

1,如果是想使用c#实现,注意传回的值是数字7: 

  1. private void CloseDialog()
  2. {
  3. string response
  4. string.Format(“<script type=’text/javascript’>window.frameElement.commitPopup(”{0}”);</script>”, 7);
  5. Context.Response.Flush();
  6. Context.Response.End();
  7. }

2.如果想使用js实现,传回值的值依然是数字7:

<script type=’text/javascript’>window.frameElement.commitPopup(“7”);</script>

下面是BasePage.aspx的接收方法:接收返回值7,并弹出。 

  1. function dialogCallback (dialogResult, returnValue)
  2. {
  3. if (returnValue != null) {
  4. alert(returnValue);//弹出窗口
  5. }
  6. return;
  7. }
原文地址:https://www.cnblogs.com/batter152/p/3596411.html