【问题标题】:Popup Window in ASP.NetASP.Net 中的弹出窗口
【发布时间】:2013-08-29 14:55:48
【问题描述】:

我对 C# 和 ASP.Net 非常陌生。有人知道如何在 Asp 中创建弹出窗口吗?

我的场景:

当我点击一个按钮时,它会检查一些状态。如果满足某个条件,则应根据状态抛出一个弹出窗口(此处:达到的百分比)。

所以点击同一个按钮会抛出 2 个单独的弹出窗口。

(您要中止未完成的合同吗?是 - 否)

(是否要完成未达到目标的合同?是 - 否)

所以当条件满足时,对话框会按照相同的按钮出现。

有人可以帮我吗? (C# 和 javascript 中的代码?)

【问题讨论】:

    标签: c# javascript asp.net popup


    【解决方案1】:

    我们使用它来调用构建/显示弹出窗口的 js 函数。希望对您有所帮助。

    protected void ibtnEdit_Click(object sender, ImageClickEventArgs e)
    {
        // do some stuff then call a js function to show a popup
        Page.ClientScript.RegisterStartupScript(this.GetType(), "clientScript", "<script     language=JavaScript>showAPopUp();</script>");
    }
    

    编辑:在aspx中定义js函数例如:

    <script>
    function showAPopUp() 
    {
        $( "#MyDialog" ).dialog( "open" );
        //alert("some simple message");
    }
    </script>   
    

    这适用于此处显示的带有 jquery ui (http://jqueryui.com/dialog/) 的代码。或者根据注释掉的行使用 alert 进行简单的弹出窗口。

    编辑 2:

    if (confirm("Confirm something?") == true) 
    {
        // they pressed ok
    }
     else
    {
        // they cancelled
    }
    

    【讨论】:

    • 所以我还需要在ASPX-File中写下一个java脚本函数?
    • 好的,现在非常感谢。我会尝试并告诉你它是否有效。
    • 嗯,它对我不起作用。你知道没有 jquery 的 javascript 解决方案吗,因为它比使用 jquery 更好。
    • 嗯,它不起作用。再次感谢。我将展示我的状态:我已添加: 在 aspx 文件中。
    • 并在按钮的事件处理程序中添加了以下内容:Page.ClientScript.RegisterStartupScript(this.GetType(), "clientScript", "");它仍然不起作用:(
    【解决方案2】:

    感谢所有试图提供帮助的人。

    我决定使用 Javascript。

    这里是 aspx-File 的代码摘录:

    <pre lang="cs">&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;
    
            String.Format = function () {
                var s = arguments[0];
                for (var i = 0; i &lt; arguments.length - 1; i++) {
                    var reg = new RegExp(&quot;\\{&quot; + i + &quot;\\}&quot;, &quot;gm&quot;);
                    s = s.replace(reg, arguments[i + 1]);
                }
                return s;
            };
            var dialogConfirmed = false;
    
            function SetDialogConfirmedFalse() {
                dialogConfirmed = false;
            }
    
            function ConfirmDialog(obj, title, dialogText) {
                if (!dialogConfirmed) { //!$('#dialog').is(':data(dialog)')
                    $('body').append(String.Format(&quot;&lt;div id='dialog' title='{0}'&gt;&lt;p&gt;{1}&lt;/p&gt;&lt;/div&gt;&quot;,
                        title, dialogText));
    
                    $('#dialog').dialog({
                        height: 110,
                        modal: true,
                        resizable: false,
                        draggable: false,
                        close: function (event, ui) { $('body').find('#dialog').remove(); },
                        buttons:
                        {
                            'Ja': function () {
                                $('#dialog').dialog('close');
                                dialogConfirmed = true;
                                if (obj) obj.click();
                            },
                            'Nein': function () {
                                $('#dialog').dialog('close');
                            }
                        }
                    });
                    $(&quot;.ui-widget&quot;).css({ &quot;font-size&quot;: +18 + &quot;px&quot; });
                }
                return dialogConfirmed;
            }</pre>
    

    在 CS-File int 他抛出此弹出窗口的事件处理程序后面的代码:

    <pre lang="cs">var script = &quot;ConfirmDialog(this, '&quot; + CommonRes.Attention +
                                 "Wollen Sie wirklich beenden?");&quot;;
                ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), script, true);</pre>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-16
      • 2011-10-23
      • 1970-01-01
      • 2013-01-03
      • 1970-01-01
      相关资源
      最近更新 更多