gpt4 book ai didi

c# - 需要像模态弹出窗口的Sharepoint

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:06 25 4
gpt4 key购买 nike

单击 GridView 中的链接时,我需要像弹出窗口一样显示 Sharepoint 2010。一旦显示模式弹出窗口并且用户选择了“保存”按钮数据库,就应该使用弹出窗口中的给定值进行更新。我怎样才能得到这个。任何想法。

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

注意:截至目前,我没有在此处添加 gridview 代码,因为我想先使用示例 html 实现它,然后再使用 GridView 。

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()" />

单击弹出窗口中的“已单击”按钮后如何调用数据库。我还需要将参数发送到弹出窗口

提前致谢

最佳答案

如果您需要在与 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. 实现一个可以监听弹出 Action 的事件,比如确定按钮

    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) { }
    }

关于c# - 需要像模态弹出窗口的Sharepoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11522440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com