Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a code that uses a confirm box from javascript. I call it from code behind using
ClientScript.RegisterClientScriptBlock(this.GetType(), "Error", "Confirm('Do you want to overwrite the file?');");
.. it does not pop-up when it passes to this line. What it does is it continues to the next line and then the dialog box pops-up when it reaches the last line of the function. Any ideas?

Thanks,
Posted

Your code is server side code, all it is doing is saying 'this script should be rendered in the response'. When you hit that line of code, it won't pop up in javascript - because it hasn't returned to the client yet - you're still running server side code.

You function will need to finish, it will register the script on the page and then it will be processed on the client by the browser
 
Share this answer
 
Comments
Franco Cipriano 4-Oct-12 11:38am    
is there a way to have it go back to the client side and then proceed to server side code?

thanks,
hi,
you need to indicate whether the script provided in the script parameter is wrapped with a <script> element block or not. Re write the code like following,
ClientScript.RegisterClientScriptBlock(this.GetType(), "Error", "Confirm('Do you want to overwrite the file?');",true);
adding "true" value indicates to add script tags. Hope this will help.
 
Share this answer
 

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