次の$.get
メソッド呼び出しAjaxCallHandler.aspx
ページを非同期で使用しています。
$.get("AjaxCallHandler.aspx?tc_id=" + tc_id, function (response) {
//get All lblStatus
var sel = "span[tc_id=" + tc_id + "]";
//alert($(sel).text() + " " + response);
$(sel).text(response);
});
AjaxCallHandler ページは、に基づいて成功/失敗tc_id is even or odd
を返します。
public partial class AjaxCallHandler : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var str = Request.QueryString["tc_id"] != null ? Request.QueryString["tc_id"] as string : string.Empty;
int tc_id;
if (int.TryParse(str, out tc_id))
{
Response.Clear(); //clears the existing HTML
Response.ContentType = "text/plain"; //change content type
if (tc_id % 2 == 0)
Response.Write("Pass"); //writes out the new name
else
Response.Write("Fail");
Response.End(); //end
}
}
}
カスタム属性を使用して、応答を Asp.Net ラベル (リピーター内に配置) にバインドするだけtc_id
で、labelStatus は更新されません。
$(sel).text(response);
Chrome コンソールで実行すると値が更新されることに注意してください 。
リピーターと の ViewState を無効にしようとしましたがlblStatus
、どちらも役に立ちませんでした。