0

Here is my situation: I am building a schedule asp.net app and i want to alert the user to the possibility of time collisions (if the user is inserting a new schedule for someone and that someone has something already scheduled for that time).

I have read and found lots of "calling JavaScript inside ASP.NET" articles here and out but they all are either showing how to call a function as soon as the user clicks something, as soon as the page loads or just showing a general alert window with just the OK button.

My question is then, how can i call a javascript messagebox with ok and cancel buttons from the middle of a function /handler in c# and have access to whatever represents those buttons so i can branch accordingly? I hear jquery messageboxes are prettier than the regular ones, how would i proceed using those instead?

sergio
  • 1,026
  • 2
  • 19
  • 43

1 Answers1

1

My question is then, how can i call a javascript messagebox with ok and cancel buttons from the middle of a function /handler in c# and have access to whatever represents those buttons so i can branch accordingly? I hear jquery messageboxes are prettier than the regular ones, how would i proceed using those instead?

This isn't really possible. Javascript happens on the client. c# function handlers happen on the server. They happen one after the other server > client > server > client, etc. You can't break out in the middle of server side code and go back to the client, and then come back to the server.

Everything that happens up to the point the form is posted happens on the client (unless there is Ajax involved), once the form is posted and you are in your c# code, everything is on the server, until the page life cycle completes and the response is returned to the client.

If you want to have a javascript confirmation function, it needs to happen BEFORE the form is posted to the server, and you need to store that result in a form field and pass it. Alternately, you can choose not to post the form at all based on the user's choice of OK or Cancel.

SouthShoreAK
  • 4,176
  • 2
  • 26
  • 48
  • While this is correct answer, ive found a workaround: use the modalpopup extender to show a custom made panel with asp buttons. Save whatever button is clicked and consume that result – sergio Apr 20 '12 at 06:16