Calling a c# method from Javascript

  • Thread starter Thread starter Steve W
  • Start date Start date
S

Steve W

I'm running codebehind pages -and this seems to be a hot question when I
google it- so, I want to throw up a javascript confirm box before the user
commits some SQL updates, and if it evals to true I want to call the c#
method to execute the SQL. Is this possible, or do I have to register the
script like I'm doing to create the Confirm box?

Thanks!
 
Steve W said:
I'm running codebehind pages -and this seems to be a hot question when I
google it- so, I want to throw up a javascript confirm box before the user
commits some SQL updates, and if it evals to true I want to call the c#
method to execute the SQL. Is this possible, or do I have to register the
script like I'm doing to create the Confirm box?

I assume your confirm box relates to a submit button? If the button handler
runs your SQL updates then you just add a client-side "onclick" handler for
the button. In the codebehind page load you could have something like...

btnRunSql.Attributes["OnClick"]="return confirm('Do you REALLY want to do
this?')";
 
Back
Top