apx.csファイルのC#で次の関数を作成しました
[WebMethod]
public static string SendForm()
{
string message = "hello world";
return message;
}
そして、関数がaspxファイルのスクリプトによって呼び出されたときに、メッセージ( "hello world")を表示しようとしています。
<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>
送信ボタンをクリックすると、「未定義」というメッセージが表示されたアラートが表示されるため、変数「msg」は未定義ですが、C#関数の「helloworld」をmsg変数に入れるにはどうすればよいですか?
ありがとう