Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9147379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:58:26+00:00 2026-06-17T10:58:26+00:00

I have a input button inside my gridview. I am capturing the button’s click

  • 0

I have a input button inside my gridview. I am capturing the button’s click event using jquery as bellow and running code behind (basically I am trying to implement the read-unread functionality of email):

  $('.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');
                    }
              }
            });

on the same page after the above event I have another event that captures row click as below:

     $("#<%=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;

Now when I click on the button the first time it works fine the event gets called but on second click the event is not called and the functionality inside tr click is run…

but when I refresh the page and do same thing and then refresh again button event is run…

Also when I comment out the ajax portion it is fine…I can’t seem to find any syntax errors in there as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:58:28+00:00Added an answer on June 17, 2026 at 10:58 am

    Change the following code

     $('.toggleBtn').click(function(e) {
    

    to the following

    $("body").on("click", ".toggleBtn", function(e){
    

    I think this is what you needed.

    Here I added the event to body since I don’t know your HTML structure. You should attach the .on to the datagridview or its parent, so that the event doesn’t have to bubble too much.

    Update:

    It is not a good idea to append events on each row, especially when there are too many rows. It will make the script too heavy. So it is recommended to use .on in these cases. In older versions of jQuery you may have to use .live instead of .on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to apply textbox blank validation on button click inside gridview in javascript?I have
I have a HTML button like <input type=button id=button onclick=showSuper() value=Click Me! /> Inside
am a newbie with jquery .. i have this html code <div id='input'> <table>
I have select and input button control inside loop. Initially input button is hidden
I have a button , <input type=button name=button> when I click on it I
I have one button inside webview as : return INPUT TYPE=\button\ type = \image\
I have following code: $boxId = 1; $explainationBox='<input type=button id=<?php echo $boxId; ?> value=send
I am using a Jquery modal window with an asp button inside. The problem
Ok, so I have this inside a form <INPUT type=text name=inputbox value=> <INPUT TYPE=button
So, I have this button inside a form: <input type=submit value=Entrar /> and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.