How to open new confirmation window (not just JS pop up) on button click, and if user response is true run the button click event code

Posted on 2007-09-30
Last Modified: 2012-06-27
Hello Experts,
I 've already opened the same question here
and the Expert doesn't know C#, so I didn't get full reply. But this is urgent, and please probably someone who is Guru in both: C# and JavaScript, or someone who has solution for my question which has been tested.
The problem is:
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 = "'WindowConfirmation.aspx?Parameter1=" + this.Variable1 + "')";
and  btnOK_Click event which is called as

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.
I thinks that 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.

Many thanks !
Question by:itproem
    LVL 5

    Accepted Solution

    On parent window use code like this:

    <script language="JavaScript" type="text/javascript">
    function proceed() {
      confirmation ='confirmation.aspx', 'confirmation', 'true');
    function yesClicked() {
      document.getElementById('contents').innerHTML = 'Yes clicked.';
    <input type="button" onclick="proceed()" value="Confirmation">
    <div id="contents"></div>

    On child use this:

    <script language="JavaScript" type="text/javascript">
    function proceedYes() {
    function proceedNo() {
    <input type="button" onclick="proceedYes()" value="Yes"> <input type="button" onclick="proceedNo()" value="No">
    LVL 14

    Expert Comment

    You can use the showModalDialog() function instead of open() function. This way, the user will not be able to interact with the opener window until the popup is closed.


      Nayer Naguib

    Author Comment

    I think the solution showModalDialog() is the answer for me if you have some exaple how I can implement this in my case by using C# and JavaScript. And I don't need anymore response from the child to parent, because I will move my C# function from parent to child, and if it is Yes it should run my C# function in the child window.This makes my life easier :)

    Now, the question is how to call window.showModalDialog() from the parent site on button click ?
     If I simply change open () to showModalDialog() it doesn't work. Probably, I need different parameters.

    Also, I have to pass parameters from the parent site to child site in the showModalDialog(), because I want to run C# function in the child site if the answer is YES. I will add on child:
    <input type="button" onclick="btnYes_Click" value="Yes">
    <input type="button" onclick="proceedNo()" value="No">
    protected void btnYES_Click(object sender, EventArgs e)
    .. My Code which is calling stored procedure in DB and using parameters from the parent site ...
            Response.Write("<script language=javascript>");

    On parent window I need to change this
               this.btnOK.OnClientClick = "'WindowConfirmation.aspx?Parameter1=" + this.Variable1 + "')";
    to the window.showModalDialog(...)

    Thanks a lot !

    LVL 14

    Expert Comment

    You can find the description of the parameters passed to showModalDialog() along with an example on the following page:


      Nayer Naguib

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
    This video teaches users how to migrate an existing Wordpress website to a new domain.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now