Link to home
Start Free TrialLog in
Avatar of itproem
itproem

asked on

How to get response to the window opener from the confirmation window ?

Hello Experts,

I have MainSite.aspx and the button btnOK that has btnOK_Click event. On the btnOK click event I want to open new web site (ConfirmationWindow.aspx) by passing a few input parameters from the main site. For example with one parameter:
           this.btnOK.OnClientClick = "window.open('WindowConfirmation.aspx?Parameter1=" + this.Variable1 + "')";
and  btnOK_Click event which is called as
           OnClick="btnOK_Click".

ConfirmationWindow.aspx contains gridview which will be bound with the stored procedures result according to the input parameters values from the MainSite.aspx and two buttons btnYES, and btnNO.

The question is, How can I get the response from the user click on btnYES or btnNO inside ConfirmationWindow.aspx back to my MainSite, and if the response is YES to finish MainSite-btnOK_Click . If response is NO then just close the ConfirmationWindow.aspx. And yes, after pressing one of the buttons either Yes or No, ConfirmationWindow.aspx should be automatically closed.
It would be nice to call return Java Script function which can return true if the user press btnYes, but question is how to do this ?
Also, is ti possible to prevent opening of more then one ConfirmationWindow.aspx. If user press once, ConfirmationWindow.aspx will open, but I want to prevent opening of the ConfirmationWindow.aspx again if it is already open.

Thanks !
Avatar of Phatzer
Phatzer
Flag of United Kingdom of Great Britain and Northern Ireland image

To communicate back to the other window, you'd do something like:

If yes:
<input type="button" onclick="window.opener.location='yes.asp'; window.close();" value="Yes">

^ That would redirect the main window to yes.asp and close the popup (in theory) :)
Avatar of itproem
itproem

ASKER

This seems ok, but please tell me what do you mean by yes.asp ?

And how can I recognize/catch value="Yes" in my MainSIte ?

Thanks
OK what you could do is this...

in the <head> of the main page:
<script language="JavaScript">
<!--

// Confirmation variable to be changed by popup window
var confirmationvar;

//-->
</script>

On your yes button in the popup:
<input type="button" onclick="opener.confirmationvar='yes'; window.close();" value="Yes">

On your no button in the popup:
<input type="button" onclick="opener.confirmationvar='no'; window.close();" value="No">

^ That would change the confirmationvar on the main page to 'yes' or 'no' and close the popup.
ASKER CERTIFIED SOLUTION
Avatar of ongngochoang
ongngochoang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itproem

ASKER

Thanks a lot, but please one more explanation :). In the MainSite.aspx.cs I have
 this.btnOK.OnClientClick = "window.open('WindowConfirmation.aspx?Parameter1=" + this.Variable1 + "')";
I will fill var confirmationvar value as you explained.
How can I use this var confirmationvar inside C# in my MainSIte, or how to assign it to some variable in the MainSite, something like  this.YesNoVar == confirmationvar

Thanks !!!!!!!!!
Avatar of itproem

ASKER

Maybe like this, to call getconfirmationvar function

<script language="JavaScript">
var confirmationvar;

function getconfirmationvar {
    return confirmationvar;
}
//-->
</script>

Thanks
If you want to call the function too, using the code you made above, then do this on your yes/no buttons:

<input type="button" onclick="opener.confirmationvar='yes'; opener.getconfirmationvar(); window.close();" value="Yes">

That should do the job.

PS: Make sure if you have either //--> or <!-- have the other one there too :), So add the <!-- above the var confirmationvar; line on the code you just done.
Avatar of itproem

ASKER

Ok, thanks, but sorry I still don't know how to pass value of the javascript variable to c# variable inside the mainSite.
Something like this (which is not correct )
 <script language="JavaScript">
     var confirmationvar;
function getconfirmationvar() {
    if (confirmationvar == 'yes') {
        '<% =  this.YesNoVar %>' = 'yes';
    }
    else {
        '<% =  this.YesNoVar %>' = 'no';
    }
}
</script>

then I will be able to use c# variable this.YesNoVar  inside OnClick="btnOK_Click" event proc.

Or to return yes/no somehow here

 this.btnOK.OnClientClick = "window.open('WindowConfirmation.aspx?Parameter1=" + this.Variable1 + "')";

Thanks a lot !
sorry i don't really work with C#, you may want to wait a little longer to see if you get a reply or take a look around at a few online tutorials
Avatar of itproem

ASKER

here is the main problem how to wait for the user response and then return true value which will in that case call the "btnOK_Click" event proc.
Avatar of itproem

ASKER

The question for ongngochoang:
What do you mean by new request from ConfirmationWindow to mainpage ?

Thanks !
is this your problem:
mainsite requests data to confirmsite then waiting for response
confirmsite will response yes or no to mainsite

if that is, my solution is:
mainsite request data to confirmsite then finish
confirm receives data from mainsite then process data and request back to mainsite
ofcourse you must have a function in mainsite to receive data from confirmsite in C# or vb.net. I dont know much about javascript