Exactly where you are planning to put the code is where it should go. So does the Ok button not register any click on the client-side?