I made following function in C# in my apx.cs file
[WebMethod]
public static string SendForm()
{
string message = "hello world";
return message;
}
And i'm trying to show the message ("hello world") when the function is called by my script in my aspx file
<script>
function SendForm() {
var msg;
msg = PageMethods.SendForm(OnSucceeded, OnFailed);
function OnSucceeded() {
alert(msg);
}
function OnFailed(error) {
// Alert user to the error.
alert("failed");
}
}
</script>
<body>
<form id="Form1" runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server"
EnablePageMethods="true" />
<fieldset id="ContactFieldset">
<input type="button" onclick="return SendForm()" value="send" />
</fieldset>
</form>
</body>
When I click on the button send I get an alert with the message 'undefined' so my var 'msg' is undefined but how can I put the 'hello world' from my C# function in the msg var?
thanks