Good day!

Can you please tell whether it is possible to make the commands in C # run first (the page code in the handler, for example), then the JavaScript , and then the commands in C # again. Schematically as follows:

 asp-команда 1; asp-команда 2; asp-команда 3; javascript asp-команда 4; asp-команда 5; 

If you write the code as I have indicated here, it turns out that asp-commands 1-5 will be executed, and after that only javascript. I just want to make sure that a confirmation-message appears to the user, and when I clicked on the "OK" button, commands 4-5 were executed, and not on "Cancel". Tell me, please, in what direction to dig!

  • It is possible, if items 4-5 are displayed in ajax. - zb '
  • The fact is that in clauses 4-5 there is a code for deleting the record from the database. Can I do this in Ajax? - chudo116
  • in Ajax, you can make a request to the server. And already on the server you can do something with the database - DreamChild
  • I seem to be beginning to understand Ajax. Advise an article with an example, or a book is good, please. The urgent task is worth it, but I did not work with Ajax before. - chudo116
  • @ chudo116 really bother to google. And anyway, if you write in ASP.NET (not MVC), are you sure that you need AJAX and direct work with JavaScript? ASP.NET event model is able to cover most of the needs when communicating with a client server - DreamChild

2 answers 2

For example, using jQuery:

  $('object_id').dialog({ modal: true, title: 'dialog_name', zIndex: 1000, autoOpen: true, width: 'auto', resizable: false, buttons: { Yes: function () { $.getJSON("action_for_yes" { Data: your_data }, function(data) { //.... }); $(this).dialog("close"); }, No: function () { $.getJSON("action_for_no" { Data: your_data }, function(data) { //.... }); $(this).dialog("close"); } }, close: function (event, ui) { $(this).remove(); } 
  • Interesting code, thanks. And can the Ajax get the number of rows in the DataGrid on the form? In ASP this is how it turns out: DataGrid.Items.Count; Can I do something about this? - chudo116
  • var rowsCount = <% = GridView1.Rows.Count%> - Max Zhukov
  • That's what I don't like about young ASP and Java encoders - they just can't understand the difference between the code running on the server and the client. - zb '
  • I think this is typical of any language that allows writing client-server applications - DreamChild
  • Nope, it seems to me that because the ASP.NET event model is able to cover most of the needs when communicating with a client server. a person is not aware of when he writes the server, and when the client part, I think with nodejs, the same thing will be, if not worse. - zb '

Alternatively, on the server:

 ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "funcJsName", "try{jscode} catch(ex){}", true); 

but there are some nuances there, it seems they will go in parallel after the js code