Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Holt App Until Javascript Confirm Dialog OK Clicked

Status
Not open for further replies.

apc2003

Programmer
Aug 29, 2003
54
0
0
GB
I'm using the following code:

Code:
string jStr = @"<script>confirm('Continue ?');</script>";
LiteralControl li = new LiteralControl(jStr);
Page.Controls.Add(li);
to display a confirm dialog but the application continues to execute even when this is shown.

How do I holt application execution until OK or cancel has been clicked on the confirm dialog?

Regards in advance...
 
This dialog is conditional it is only shown when a particular validate returns false and then the user has to choose to continue or cancel. If the validate returns true it is not to be shown.

Can anyone suggest away to make this work as an Form OnSubmit isn't really what i need to do...

Regards in advance...
 
You can create scripts conditionally. You can register them to controls conditionally, as well.

Are you saying that you want:

1) A webform that contains a confirm script, and only submits the form when a user clicks "OK", and cancels execution if the user clicks "Cancel", or

2) A webform that a. submits to the server b. conditionally returns a confirm script c. prompts the user to confirm and d. submits or not (a second time) for further processing, based on what the user selects?



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
I have a ASP.net application that upon a Save button:

1. Validates certain criteria in a validate method that returns true or false.

2. If the validate returns true the Save carries on as normal and does its work.

3. If the validate returns false I need to show a warning (Javascript confirm) and allow a user to continue by clicking OK or cancel the save by clicking false.

I have managed to get the Warning message to appear but cannot make the application execution holt until the user chooses what to do. If the user clicks cancel the app save method need to terminate.

Regards in advance...
 
I don't mean to be rude so please don't take it that way... I appreciate all the help. :)
But I do understand how Server-side vs. Client-side code executes / runs.

OK... :) Here is the full scenario and what we need to accomplish!

We have a Save button in C# side of the asp.net web application.

Before the Save does its work against a SQL Database we run a method that does some checks and returns true or false.

Based on this return value if it is false I need to show a dialog asking the user to continue or cancel the save, this is the point where I need to hold code execution.

If the check method returns true the save should carry on without showing the dialog.

I don't think it can be done using the HTML side of the application.

We need to fire the code based on the return value of my check method. If the Dialog is shown we need to stop the code execution and catch the user input, ok or cancel, and based on this we need to take action, continue with save or cancel the save.

Code Example of how the save method is laid out and how we need the Dialog to display and holt the execution:
Code:
// C# Side Code
private bool CheckMethod()
{
  try
  {
    if (something)
      return true
    else
      return false
  }
  catch (Exception ex)
  {
    throw ex;
  }
}

private void Save()
{
  try
  {
    bool ok = ChechMethod()

    if(!ok)    
    {
      bool continueSave = // SHOW DIALOG AND WAIT FOR USER INPUT THEN RETURN USER INPUT OK (True) / CANCEL (False)
      
      if (!continueSave)
        return; // Cancel Save.
    }

    // DO SQL DATABASE WORK...
  }
  catch (SqlException sqex)
  {
    throw sqex;
  }
  catch (Exception ex)
  {
    throw ex;
  }
}
I'm not sure if what we are doing can be done in this way but we need a solutions to this problem that will give us the result shown in the above code.

Thanks again for any and all help given... :)
 
You simply CANNOT do it that way. The Server CANNOT throw a prompt the user's browser, execute it, and return the results back to the server's running code.

It's a client-server application. Server runs, generates HTML and/or JavaScript, and RETURNS CONTROL to the CLIENT. The CLIENT then runs, the user clicks this, selects that, then ENDS CONTROL and submits back to the SERVER.

I've given you a complete breakdown on what you need to do in at least two other posts. I'M not trying to be rude, but you're NOT LISTENING.



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
I re-read my last post, and don't like how over-the-top it seems. Sorry.

Think of it this way, if you could halt execution of your code, what would be happening in the browser? Your user would be waiting indefinitely for the server to finish. You can indeed write a script to show a confirm, but until your server code finishes, the response would never get to the browser.



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Thomas D. Greer... No worries all help is appreciated.

If it is ok we would like your opinion on this piece of logic...

On the Save button:
1. Using RegisterStartUpScript to register the Javascript Confirm function.
2. If the user clicks ok submit the page using document.forms[0].submit().
3. If the user clicks cancel don't submit the page.

We found this on website and are looking for a second opinion.

Thanks in advance...
 
Yes, that's the approach I suggested for you, twice, in the other forum. That's what you have to do, if you must perform your validation on the server.

If you read further back in the thread(s), you'll see that I also suggested a more efficient approach, which would result in less round-trips to the server.

That approach is to move your validation from the "server Save button", to a client script instead.

So the most efficient program flow would be:

1) User navigates to a page which contains:
a. the data-entry form.
b. a JavaScript Validation script to validate the form
c. a JavaScript "confirm" script

2) User fills out the form, clicks "Save".
3) The JavaScript validation occurs
4) Validation succeeds, submit the form to the server
5) Server commits data to the database

-or-

4) Validation fails
5) JavaScript confirm script runs
6) User confirms, submit the form to the server
7) Server commits data to the database

-or-

4) Validation fails
5) JavaScript confirm script runs
6) User cancels

In this approach, the program control goes from:

1) Server to Browser (display page)
2) Browser to Server (submit form)

In the other approach, program control goes from:

1) Server to Browser (display page)
2) Browser to Server (submit/validate form)
3) Server to Browser (register the confirm script)
4) Browser to Server (submit form again)




Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top