Click here to Skip to main content
14,735,210 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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 fullfilled a popup shall be thrown due to the state (here: achieved procentages). 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?)

KR


additional question copied from answer below
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?
Posted
Updated 29-Aug-13 23:52pm
v2
Comments
[no name] 29-Aug-13 11:01am
   
You won't do this in C#. You need to use client side scripting to do this. http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx
0xMoonstar 29-Aug-13 11:24am
   
I want to do it with Javascript, but don't have any experience in this language... I only know that you can add a javascript script in the aspx-File. I need also have access to the decision of the user having clicked the popup over the C# code and exactly in the event handler of the button throwing this pop up.
[no name] 29-Aug-13 13:27pm
   
"I want to do it with JavaScript" okay so go ahead and do that then. Did you even bother looking that the Ajax Toolkit that does exactly what you are trying to do?

if (confirm('Question')) {
    
} else {
   
}



Use simple Javascript!
   
Comments
0xMoonstar 29-Aug-13 11:13am
   
Yeah cool thx, but how do I catch the result like what the user pressed, whether yes or cancel?

Because it has to be linked with the C#-Code where I check whether the condition was fullfilled to throw this popup in the event handler of the button which throws this pop up.
Thanks everybody who tried to help.

I decided to use Javascript.

Here is a code excerpt of the aspx-File:

<script type="text/javascript" language="javascript">

        String.Format = function () {
            var s = arguments[0];
            for (var i = 0; i < arguments.length - 1; i++) {
                var reg = new RegExp("\\{" + i + "\\}", "gm");
                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("<div id='dialog' title='{0}'><p>{1}</p></div>",
                    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');
                        }
                    }
                });
                $(".ui-widget").css({ "font-size": +18 + "px" });
            }
            return dialogConfirmed;
        }


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

var script = "ConfirmDialog(this, '" + CommonRes.Attention +
                             "Wollen Sie wirklich beenden?");";
            ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), script, true);


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!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900