Ramco Ramco

Ramco Ramco

  • 442
  • 3.4k
  • 517.4k

Web Method not getting called

May 16 2023 12:53 PM

Hi

   I am trying below code but WebMethod not getting called

<script>
            function GetModuleData(e) {
                var currentRow = $(e).closest("tr");
                var rp;
                // rp = currentRow.find("td:eq(0)").text();
                var table = document.getElementById("grdPlanning"), rIndex, cIndex, track;
                // table rows
                for (var i = 1; i < table.rows.length; i++) {
                    // row cells
                    for (var j = 0; j < table.rows[i].cells.length; j++) {
                        table.rows[i].cells[j].onclick = function () {
                            rIndex = this.parentElement.rowIndex;
                            cIndex = this.cellIndex;

                            if (cIndex > 0) {
                                Mobile = $('table tr th:eq(' + (cIndex) + ')').text();
                                BookId = currentRow.find("td:eq(0)").text();
                                var str = Mobile;
                                const result = str.split(/[()]/);
                                var res1 = result[0];
                                var res2 = result[1];
                                document.getElementById('hdfBookId').value = BookId;
                                document.getElementById('hdfMobile').value = res2;
                            };
                        };
                    }
                }
                $.ajax({
                    type: "POST",
                    url: "AddRecommendedBooks.aspx/getPopUp",
                  /*  *//*data: JSON.stringify({ bookId: BookId, mobile: res2 }),*/
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        // Handle the response if needed
                        console.log("C# code executed successfully.");
                    },
                    error: function (xhr, textStatus, errorThrown) {
                        // Handle the error if needed
                        console.log("Error executing C# code:", errorThrown);
                    }
                });
            };
        </script>
[WebMethod]
        protected void getPopUp()
        {
            try
            {
                    BALBooks bALBooks = new BALBooks();
                    BALStudents bALStudents = new BALStudents();
                    StudentDetail Result = bALStudents.GetStudentDetailByLoginID(bALStudents.GetStudentIDByMobile(hdfMobile.Value));
                    ltrlHead.Text = Result.Name;
                    ltrlHead.Text = ltrlHead.Text + " : " + bALBooks.GetBookTitle(Convert.ToInt32(hdfBookId.Value));

                    BindData(Convert.ToInt32(hdfBookId.Value), Result.LoginCode);
 
            }
            catch (Exception ex)
            {
                Utility.SaveErrorLog(ex.Message, System.IO.Path.GetFileName(Request.Path), System.Reflection.MethodBase.GetCurrentMethod().Name, Convert.ToInt32(hdfLoginCode.Value));
                ShowMessage("Oops...", ex.Message, "error");
            }
        }

Thanks


Answers (2)