如何阻止模式对话框弹出窗口显示在后面的sharepoint代码中

时间:2012-12-28 13:49:57

标签: jquery visual-studio-2010 sharepoint sharepoint-2010

我在Visual Web Part中的jQuery / javascript中创建了一个Modal Dialog Popup,每次加载页面时都会显示。弹出窗口中有一个提交按钮,单击该按钮时,我会在自定义列表中存储用户名和确认日期。有效的jQ代码:

 <script language="javascript" type="text/javascript"  src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">

</script>
<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        ExecuteOrDelayUntilScriptLoaded(openDialog, "SP.js");        
    });

    //open dialog



    // Call openDialog method on button click or on page load  

    function openDialog() {
        //alert("In funciton opendialog");
        var options = {

            //html: divModalDialogContent,  // ID of the HTML tag

            // or HTML content to be displayed in modal dialog

            width: 400,

            url: "/_layouts/ModalDialog1/ModalDialog.aspx",

            height: 125,

            title: "Acknowedgement Popup",

            dialogReturnValueCallback: dialogCallbackMethod,  // custom callback function

            allowMaximize: false,

            showClose: false

        };
        SP.UI.ModalDialog.showModalDialog(options);

    }


    // Custom callback function after the dialog is closed

    function dialogCallbackMethod(result, returnValue) {

        alert("dialogResult" + result + "nreturnValue" + returnValue);
                if(result == SP.UI.DialogResult.OK)
         {
         alert("You chose the OK button");
         //document.title = returnValue;
         }

        if(result == SP.UI.DialogResult.cancel)
         SP.UI.Notify.addNotification("You chose the Cancel button");
         }

    }

</script>


现在,我正在使用此代码添加列表中的用户名。我使用aspx页面将其存储在列表中,该页面在弹出窗口中单击按钮时触发:


protected void Button1_Click(object sender, EventArgs e)
    {
        Context.Response.Write(@"<script type='text/javascript'>
                                alert('Thanks for acknowledging!');
                                window.frameElement.commitPopup();
                                </script>");
        Context.Response.Flush();
        Context.Response.End(); 

        string username;
        using (SPSite site = new SPSite(SPContext.Current.Web.Url))
        {
            site.AllowUnsafeUpdates = true;
            using (SPWeb web = site.RootWeb)
            {
                web.AllowUnsafeUpdates = true;
                SPUser user = web.CurrentUser;

                username = user.LoginName.ToString();


                //adding list item
                SPList l = web.Lists["Acknowledgements"];
                SPListItem li = l.Items.Add();
                li["User"] = username;
                li["Acknowedgement Date"] = System.DateTime.Today;
                li.Update(); 

            }


        }

现在客户端要求是在月初显示模式对话框弹出窗口,如果自定义列表中已存在用户名,则不显示该月份的模式对话框弹出窗口。我用Google搜索并了解了registertartupscript,你可以在后面编写javascript代码并使用它,但它无效。我打算比较列表中的用户名和当前登录的用户名,如果他已经确认,则不显示弹出窗口,但是它打败了我如何实现这一点,而且,javascript在客户端。

string Script = @"function openDialog() { var options={
                    width:400,
                    url: '/_layouts/ModalDialog/ModalDialog.aspx', height:125,
                    title: 'Acknowedgement Popup',
                    dialogReturnValueCallback: dialogCallbackMethod, 
                    allowMaximize: false,
                    showClose: false
                    };
                    SP.UI.ModalDialog.showModalDialog(options);
                     }";Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "openDialog", Script, true); 


我是否正确地使用这一切?我是SharePoint的新手,所以请帮忙。 这让我陷入了困境。在此先感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在你的标记中,你可以添加一个Literal作为JS标志变量的占位符...确保在你的openDialog函数之前添加它:

<asp:Literal runat="server" ID="DlgFlag"></asp:Literal>

在你的代码隐藏中,检查列表,如果找到用户名,则输出一个标志到文字:

if (isUsernameInListAlready)
{
    DlgFlag.Text = "<script type=\"text/javascript\">var dlgFlag = true;</script>";
}

在你的openDialog函数中,检查顶部的这个标志,如果标志存在,只需退出w / o打开对话框:

function openDialog() {
    if (dlgFlag) return;

    //alert("In funciton opendialog");
    var options = {
    ...
相关问题