Popup Window in ASP.Net

孤街浪徒 提交于 2019-12-13 02:57:05

问题


im very new to C# and ASP.Net. Does anybody know how to create a popup in Asp?

My scenario:

When I click on a button, it checks some states. If a condition is being fulfilled a popup shall be thrown due to the state (here: achieved percentages).

So 2 invidual Popup Windows shall be thrown by clicking the same button.

(Do you want to abort the contract, which wasn't completed? Yes - No)

(Do you want to completed the contract, which hasn't achieved the target? Yes - No)

So the dialog boxes shall appear according for the same button when the condition was fullfilled.

Can anybody help me? (Code behind in C# and javascript?)


回答1:


We used this to call a js function which built/shows a popup. Hope it is of some help.

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>");
}

Edit: In the aspx define the js function for example:

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

Which would work with code like shown here with jquery ui (http://jqueryui.com/dialog/). Or use alert for a simple popup as per the commented out line.

Edit 2:

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



回答2:


Thanks everybody who tried to help.

I decided to use Javascript.

Here is a code excerpt of the 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>

Code behind the in CS-File int he Eventhandler which throws this popup:

<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>

My next question is: How can I get the return value what was being pressed of the javascript function to use it in the cs-File?

Thanking you in anticipation!



来源:https://stackoverflow.com/questions/18514346/popup-window-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!