RegisterStartupScript isn't stopping server-side execution to run script on the client and wait for a response, all it is doing is adding the javascript you specify to the output and continues on. The browser only gets the html (and therefore runs the js) after all of your server code has finished running. There are a few ways to handle getting a confirmation to continue something, it might involve splitting your task into two distinct steps.
Asking the user to confirm that they want to continue with an action | The ASP.NET Forums[
^]
The technique you're using can't be "fixed", you're going to have to re-architect your process.