I have a basic <ul> <li> structure in an ASP.NET page. Now I am getting dynamic records in this <li>, and my problem is, when the user clicks on the next button, it should check for the last page, and accordingly display an alert message, if last page has been reached.
I am getting the totalPages in jQuery, when I place the alert I get the message for TotalPage, but when I write the same code in an if condition, it does not evaluate. Below is my JavaScript function.
var totalPages = -1;
function MostPopularSlideShows(currentPage, pager, mostpopular_data) {
$.ajax({
type: "POST",
url: "SlideShowAdmin/Ajax/SlideShow.aspx/MostPopularSlideList",
dataType: "json",
contentType: "application/json",
data: "{\"CurrentPage\":'" + currentPage + "'}",
success: function (data) {
var result = data.d;
var totalPages = result[0].TotalPages;
//alert(totalPages); This works fine.
if (currentPage > totalPages) //Here it never evaluates
{
alert("You have reached last page");
currentPage -= 1;
}
else {
$("#" + pager).html(currentPage + "/" + result[0].TotalPages);
$("#" + mostpopular_data).html("");
$.each(result, function (index, item) {
$("#" + mostpopular_data).append("<li><img src=\"images/most_popr_pic1.jpg\" width=\"153\" height=\"90\" alt=\"\" class=\"floatleft\" /><h6>" + item.SlideShowName + "</h6><h3><a href=\"#\">" + item.Title + "</a></h3><h4>" + item.Description + "</h4></li>");
})
}
},
error: function (data) {
alert("Cannot Get Most Popular SlideShow, Server Threw below error:\n" + data.responseText);
}
});
}
Below is my Ajax function.
[WebMethod]
public static SlideList[] MostPopularSlideList(int CurrentPage)
{
List<SlideList> list = new List<SlideList>();
DataSet d = SqlHelper.ExecuteAdapterForDataSet("user_MostPopularSlideShow", new SqlParameter[] { new SqlParameter("@PortalID", PortalId), new SqlParameter("@CurrentPage", CurrentPage) }, CommandType.StoredProcedure);
foreach (DataRow r in d.Tables[0].Rows)
{
SlideList _slide = new SlideList();
_slide.Id = Convert.ToInt32(r["Id"]);
_slide.SlideShowId = Convert.ToInt32(r["SlideShowId"]);
_slide.Description = r["SlideDescription"].ToString();
_slide.CreatedDate = (r["CreatedDate"]).ToString();
_slide.Thumbnail = r["Thumbnail"].ToString();
_slide.Total = Convert.ToInt32(d.Tables[1].Rows[0]["TotalRows"]);
_slide.TotalPages = Convert.ToInt32(d.Tables[1].Rows[0]["TotalPages"]);
_slide.Title = r["SlideTitle"].ToString();
_slide.SlideShowName = r["SlideShowName"].ToString();
list.Add(_slide);
}
return list.ToArray();
}
Why doesn’t it evaluate for totalPages?
Actually, the following code block never executes, I think.
Since
current pagecan be at mosttotalPages, it can be equality checked like: