グリッドビュー内に入力ボタンがあります。以下のようにjqueryを使用してボタンのクリックイベントをキャプチャし、コードビハインドを実行しています(基本的に、電子メールの読み取りと読み取りの機能を実装しようとしています)。
$('.toggleBtn').click(function(e) {
btnUnreadClicked = true;
$.ajax({
type: "POST",
url: "ClaimDetails.aspx/BtnOpenPDF",
data: "{'id': '" + letterid + "','anchText': '" + anchText + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (msg) {
if (msg.d == 'Read') {
$tr.removeClass('unreadGridRow');
//update unread text to date time now
var d = new Date();
var replaceUnread = unreadColumn.toString().replace("Unread", d.format("dd/MM/yyyy"));
$tr.html(replaceUnread);
//update claim letter counts only
var parentRow = document.getElementById('__' + parentrowid).innerHTML;
var lblUnreadDocCount = $('#__' + parentrowid).find('#lblUnreadDocCount').text();
var finalCount = parseInt(lblUnreadDocCount) -1 ;
if(finalCount >= 0)
{
$('#__' + parentrowid).find('#lblUnreadDocCount').text(finalCount);
}
if(finalCount == 0 )
{
//remove the class
$('#__' + parentrowid).removeClass('unreadGridRow');
}
//get count of overall documents and subtract from it
var notification = $("#NewLetter3");
var numb = notification.text().match(/\d/g);
var finaldigits = numb.toString().replace(",", "");
var finalTotalDocsCount = parseInt(finaldigits) - 1;
if(finalTotalDocsCount >= 0)
{
//notification.text(notification.text().replace(numb, finalTotalDocsCount));
notification.html("You have " + finalTotalDocsCount + " unread Documents. Please click here to view");
//document.getElementById("NewLetter2").innerHTML = notification.text();
if(finalTotalDocsCount == 0)
{
$("#NewLetter2").hide();
}
}
$tr.find(".toggleBtn").text('Un-read');
}
else if (msg.d == 'Un-read') {
$tr.addClass('unreadGridRow');
//update unread text to date time now
var unreadDate = new Date();
var replaceRead = unreadColumn.toString().replace("Unread", unreadDate.format("dd/MM/yyyy"));
$tr.html(replaceRead);
//update claim letter counts only
var unreadparentRow = document.getElementById('__' + parentrowid).innerHTML;
var lblUnreadDocCountUnread = $('#__' + parentrowid).find('#lblUnreadDocCount').text();
var finalCountUnread = parseInt(lblUnreadDocCountUnread) + 1 ;
if(finalCountUnread >= 0)
{
$('#__' + parentrowid).find('#lblUnreadDocCount').text(finalCountUnread);
}
if(finalCountUnread > 0 )
{
//remove the class
$('#__' + parentrowid).addClass('unreadGridRow');
}
//get count of overall documents and subtract from it
var Unreadnotification = $("#NewLetter3");
if(Unreadnotification.text() == "" ) { Unreadnotification.html("You have 0 ");}
var Unreadnumb = Unreadnotification.text().match(/\d/g);
var Unreadfinaldigits = Unreadnumb.toString().replace(",", "");
var finalTotalDocsCountUnread = parseInt(Unreadfinaldigits) + 1;
if(finalTotalDocsCountUnread >= 0)
{
if(finalTotalDocsCountUnread >= 0)
{
$("#NewLetter2").show();
}
//notification.text(notification.text().replace(numb, finalTotalDocsCount));
Unreadnotification.html("You have " + finalTotalDocsCountUnread + " unread Documents. Please click here to view");
//document.getElementById("NewLetter2").innerHTML = notification.text();
}
$tr.find(".toggleBtn").text('Read');
}
}
});
上記のイベントの後の同じページに、以下のように行クリックをキャプチャする別のイベントがあります。
$("#<%=gvClaimDtSentDate.ClientID%> tr:has(td)").click(function (e) {
if( $(this).closest('tr').hasClass('parent'))
{
if(btnUnreadClicked == false)
{
// do stuff related to row click
}
btnUnreadClicked = false;
これで、ボタンを最初にクリックすると正常に機能しますが、2回目のクリックではイベントは呼び出されず、trクリック内の機能が実行されます...
しかし、ページを更新して同じことを行ってから、もう一度更新すると、ボタンイベントが実行されます...
また、ajaxの部分をコメントアウトすると、問題ありません...そこにも構文エラーが見つからないようです。