最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Popup Window in ASP.Net - Stack Overflow

programmeradmin2浏览0评论

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 pleted? Yes - No)

(Do you want to pleted 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?)

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 pleted? Yes - No)

(Do you want to pleted 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?)

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Aug 29, 2013 at 14:55 MoonstarMoonstar 2471 gold badge5 silver badges13 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 0

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./dialog/). Or use alert for a simple popup as per the mented out line.

Edit 2:

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

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>
发布评论

评论列表(0)

  1. 暂无评论