c# - Easy Async Callback Alternative -


i need logic...

currently:

  1. a user inputs data in page from.
  2. the user clicks submit.
  3. javascript places data in hidden input field.
  4. the page postback (reloads)
  5. c# registers postback , gets hidden javascript field.
  6. c# puts in database.

the problem above reloading of webpage. not want that. have played around callback script not working (i have question open on trying debug that).

my question alternatives accomplish steps defined above without callback or postback? there way call server-side function on demand client side function? (i know callbacks should thing, mine not working)

if there no such alternative, why callbacks complicated (from novice's point of view)? why can not call callback like:

if (iscallback)         {             string test = request.form["savetest"];             //do stuff         } 

thank you. also, please not 'close' or mark down question without first critiquing me. thanks.

here's simplest example can think of, uses ajax asp.net.

  • using jquery, because simplifies making ajax request
  • not using asp.net ajax, because adds abstraction on top of core technology, , not way start learning

first, userinput.aspx

<html>     <input type='text' id='someuserinput' />     <input type='submit' value='submit' id='submitbutton' />      <script src='http://code.jquery.com/jquery-1.10.2.js'></script>     <script>           // wait document load         $(document).ready(function() {              // handle button click             $("#submitbutton").on("click", function(e) {                  // stop page submitting, can make ajax call                 e.preventdefault();                  // retrieve user input                 var userinput = $("#someuserinput").val();                  // make ajax request                 $.post("ajaxhandler.aspx", { savetext: userinput }, function(response) {                      // handle response server                     alert("request complete.  result: " + response);                 });             });         });     </script> </html> 

second, ajaxhandler.aspx

<%@ page language="c#" %>  <%     string userinput = request.params["savetext"];      // use input here      response.write("done, maybe?"); %> 

Comments