Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. what is the error in this code ?

what is the error in this code ?

Scheduled Pinned Locked Moved ASP.NET
questionjavascriptsysadmintoolshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ahmed eldeghedy
    wrote on last edited by
    #1

    <body onunload="CallMyEnd()"> <script type="text/javascript" language="javascript"> function CallMyEnd() { // call server side method alert(PageMethods.GetName()); } </script> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"/> ------------------------- and my methods CS. [WebMethod] public static string GetName() { return "1111111"; } the explorer return alert undefined what is the error in this code ? i try the script on head and now in body the same error ?

    ahmed eldeghedy

    G 1 Reply Last reply
    0
    • A ahmed eldeghedy

      <body onunload="CallMyEnd()"> <script type="text/javascript" language="javascript"> function CallMyEnd() { // call server side method alert(PageMethods.GetName()); } </script> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"/> ------------------------- and my methods CS. [WebMethod] public static string GetName() { return "1111111"; } the explorer return alert undefined what is the error in this code ? i try the script on head and now in body the same error ?

      ahmed eldeghedy

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      The method call is asynchronous. You need to specify a callback function in the call:

      PageMethods.GetName(callback);

      In the callback function you get the result:

      function callback(result, context, method) {
      alert(result);
      }

      You can also specify another callback function for a failed AJAX call. The method parameter in the callback is the name of the server function called, so you can use the same callback for several page methods. (I never used AJAX page methods before, so I learned something new this day too. :))

      Despite everything, the person most likely to be fooling you next is yourself.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups