Hi
I am trying below code but WebMethod not getting called
[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
Mohamed Azarudeen ZPosted May 16, 2023, 1:24 PM
it seems that you are attempting to call a WebMethod named
getPopUpfrom yourAddRecommendedBooks.aspxpage using AJAX. However, there are a few points to consider:WebMethod Accessibility: Ensure that the
getPopUpmethod is declared aspublic staticin your code-behind file (code-behind forAddRecommendedBooks.aspx).ScriptManager: If you are using an ASP.NET Web Forms application, make sure you have a ScriptManager control on your page. The ScriptManager enables the page to handle AJAX requests.
PageMethods: If you're not using a ScriptManager, you can try using the
PageMethodsobject to call the WebMethod. Modify your AJAX call as follows:Replace the above AJAX call with the following code:
Ensure that the
EnablePageMethodsattribute is set totruein your ScriptManager or in the page directive (EnablePageMethods="true").Additionally, make sure your web application is running on a server that supports ASP.NET AJAX, as the WebMethod call won't work with static HTML files.
Amit MohantyPosted May 16, 2023, 1:22 PM
Make sure that the
AddRecommendedBooks.aspxpage has theScriptManagercontrol added to it. TheScriptManagercontrol is required for enabling ASP.NET AJAX functionality.