需要Sharepoint像模态弹出窗口

时间:2012-07-17 12:28:33

标签: c# .net popup modal-dialog sharepoint-object-model

点击网格视图中的链接时,我需要像弹出窗口一样显示Sharepoint 2010。显示模态弹出窗口并且用户选择了“保存”按钮后,应使用弹出窗口中的给定值更新数据库。我怎么能得到这个。任何想法。

截至目前,我正在使用下面的代码来获取它但不知道如何在弹出窗口中单击按钮时将值传递给数据库

注意:到目前为止,我没有在这里添加gridview代码,因为我想首先使用示例html实现它,然后想要使用网格视图。

Java脚本

function openDialog() {

    var options = {

        html: divModalDialogContent,  // ID of the HTML tag

        // or HTML content to be displayed in modal dialog

        width: 600,

        height: 300,

        title: "My First Modal Dialog",

        dialogReturnValueCallback: dialogCallbackMethod,  // custom callback function

        allowMaximize: true,

        showClose: true

    };

    SP.UI.ModalDialog.showModalDialog(options);

}

//Results displayed if 'OK' or 'Cancel' button is clicked if the html content has 'OK' and 'Cancel' buttons

function onDialogClose(dialogResult, returnValue) {

    if (dialogResult == SP.UI.DialogResult.OK) {

        alert('Ok!');

    }

    if (dialogResult == SP.UI.DialogResult.cancel) {

        alert('Cancel');

    }

}

// Custom callback function after the dialog is closed

function dialogCallbackMethod() {

    alert('Callback method of modal dialog!');

}

HTML

<div id="divModalDialogContent">

    Hello World!

    <input type="button" value="OK"onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, 'Ok clicked'); return false;"

        class="ms-ButtonHeightWidth" />

    <input type="button" value="Cancel"onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, 'Cancel clicked'); return false;"

        class="ms-ButtonHeightWidth" />

        <asp:Button runat="server" ID="btnClicked" Text="Clicked" 
        onclick="btnClicked_Click" />

<input type="button" value="Open" onclick="openDialog()" />

如何在弹出窗口中单击“单击”按钮调用db。此外,我需要发送参数弹出

提前致谢

2 个答案:

答案 0 :(得分:1)

如果您需要ok,请在弹出屏幕上取消或提交按钮事件,该事件与Sharepoint列表/库或sql数据库交互,然后您需要在弹出窗口中实现事件。检查以下步骤: -

  1. 您的弹出页面应该继承“Microsoft.SharePoint.WebControls.LayoutsPageBase” 应具备此功能: -

    protected void EndOperation(int result, string returnValue)
    {
      string closeModal = String.Format(CultureInfo.InvariantCulture,
      "<script type=\"text/javascript\">window.frameElement.commonModalDialogClose
      ({0}, '{1}');</script>", new object[] { result, returnValue });
      this.Page.ClientScript.RegisterStartupScript(base.GetType(),
      "CreatePopup", closeModal, false);
    }
    
  2. 实现一个可以监听弹出操作的事件,如ok按钮

    public delegate void AddEventHandlerToSPDialogEvent(object sender, PDialogEventHandler e);
    public class SPDialogEventHandler : EventArgs
    {
      public int dialogResult { get; set; } // 0 or 1
      public string ReturnValues { get; set; } // can be url or any success/error message
      public SPDialogEventHandler(int result, string list)
      {
        ReturnValues = list;
        dialogResult = result;
      }
    }
    
  3. 在弹出窗口中通过按钮操作调用此事件。例如:

    public event AddEventHandlerToSPDialogEvent ResultOk;
    protected void CancelBtn_Click(object sender, EventArgs e)
    {
        try
        {
            int dialogResult = 0;
            if (this.ResultOk != null)
            {// Here dialogResult is 0. that means we have clicked on cancel button
                ResultOk(this, new SPDialogEventHandler(dialogResult,"Action Cancelled"));
            }
        }
        catch (Exception ex) { }
    }
    

答案 1 :(得分:0)

您可以使用Ajax控件工具包,然后您应该查找模式弹出扩展器。

就像你可以将.net控件添加到overlay / modal overlay中并获取代码中的值

了解更多信息,请点击此处 http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx

SP Popup Open a modal/pop up form in Sharepoint 2010 with asp.net controls in it