简体   繁体   English

sharepoint 2010弹出窗口

[英]sharepoint 2010 popup window

Have some troubles with calling js from code behind. 从后面的代码调用js会遇到一些麻烦。 This is my js code 这是我的js代码

 function showDialog() {
            var options = {
                url: 'DialogWindow.aspx',
                width: 600,
                height: 200,
                title: 'Test',
                showClose: true,
                dialogReturnValueCallback: dialogReturned
            };
            SP.UI.ModalDialog.showModalDialog(options);
        }
        function dialogReturned(dialogResult, returnValue) {
            if (dialogResult == SP.UI.DialogResult.OK) alert("OK");
            else alert("CANCEL");
        }

And this is my c# code to call js function 这是我的C#代码来调用js函数

if (!WriteDataToSm())
            {
               //Error Handling
                string script = "<script language='javascript'>showDialog()</script>";
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "Register", script);
            }

but i'm getting a js error: 但我收到一个js错误:

Uncaught TypeError: Cannot read property 'hiddenButtonValueBeforeDialog' of undefined 

but when i'm create a button and call js function showDialog() inside onclick event. 但是当我创建一个按钮并在onclick事件中调用js函数showDialog()时。 Everything works fine. 一切正常。 pls advide what could be the reason of this? 请提出这可能是什么原因?

I am using this line of code to execute javascript from code behind: 我正在使用以下代码行从后面的代码执行javascript:

page.ClientScript.RegisterStartupScript(page.GetType(), "idicosNotify", "$(function () { ExecuteOrDelayUntilScriptLoaded(function () { SP.UI.Notify.addNotification(\"" + message + "\", false); }, \"sp.js\"); });", true);

When you can call your javascript function with a button then there is nothing wrong with it. 当您可以通过按钮调用javascript函数时,则没有任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM