what is the error in this code ?
-
<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
-
<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
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.