ラジオボタンリストを持つjquery uiダイアログがあります。ユーザーが [OK] をクリックしたときにサーバー側のメソッドを呼び出す必要があり、選択した値を渡す必要があります。ajaxメソッドを呼び出して、選択した値をパラメーターとして渡すことで試してみました。これはうまく機能しました (値が渡されました) が、メソッドから Cookie にアクセスできませんでした (エラーが発生しました - リクエストはこのコンテキストでは利用できません)。これは、これが ajax リクエストであることを意味します。コードは次のとおりです。
$("#dialogReject").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Reject": function () {
var value = $(this).find('input:checked').val();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/myPage.aspx/RejectDocumentWM",
data: "{'rejectReason':'" + value + "'}",
dataType: "json",
success: function (data) {
alert('success');
},
error: function (result) { alert('error'); }
});
$(this).dialog('close');
},
Cancel: function () {
$(this).dialog("close");
}
}
});
RejectDocument():
[WebMethod]
public static void RejectDocumentWM(string rejectReason)
{
MyNamespace.myPage page = new MyNamespace.myPage();
page.RejectDocument(rejectReason);
}
protected void RejectDocument(string rejectReason)
{
batch batch = (batch)Session["Batch"];
if (client.RejectDocument(batch.GetCurrentDoc().icn, rejectReason, Request.Cookies["username"].Value)) //here is where I get the error
{
NextDocument();
}
}
値を隠しフィールドに入れてから、サーバー側のメソッドを呼び出すボタンクリックを呼び出すことで、それを試しました。ここでの問題は、クライアント スクリプトで適切に設定されていても、隠しフィールドの値が常に空白だったことです。そのためのコードは次のとおりです。
$("#dialogReject").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Reject": function () {
var value = $(this).find('input:checked').val();
$('[id$="hdfRejectReason"]').val(value); //this sets properly
$('[id$="btnRejectDoc"]').click();
$(this).dialog('close');
},
Cancel: function () {
$(this).dialog("close");
}
}
protected void btnRejectDoc_Click(object sender, EventArgs e)
{
batch batch = (batch)Session["Batch"];
if (client.RejectDocument(batch.GetCurrentDoc().icn, hdfRejectReason.Value, Request.Cookies["username"].Value))
//hdfRejectReason.Value is blank
{
NextDocument();
}
}
私に何かアイデアはありますか?私は途方に暮れています。ありがとう!