Recently, I encountered an issue with a JavaScript code designed to enable full gridview row clicking to check a checkbox within the same row. This code is located in an external file.
$(document).ready(function () {
$('tr.dataRow').on('click', function () {
var checked = $(this).find('input[id*=chkBusinessSelected]').prop('checked');
$(this).find('input[id*=chkBusinessSelected]').prop('checked', !checked);
});
});
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
$('tr.dataRow').on('click', function () {
var checked = $(this).find('input[id*=chkBusinessSelected]').prop('checked');
$(this).find('input[id*=chkBusinessSelected]').prop('checked', !checked);
});
});
Within the User Control code behind, you can find:
protected void grdBusiness_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.CssClass = "dataRow";
}
}
This script is enclosed in an Update Panel to prevent full Postback. Its purpose is to allow for multiple selection of items within a gridview. Despite its initial success, when integrating the User Control into a parent page with its own Update Panel, issues arose.
While utilizing the gridview row clicking feature and subsequently attempting to click another button outside of the user control for processing, the checkbox clicking functionality ceased to work. The JavaScript code appeared to stop functioning altogether.
I conducted an experiment by removing the UpdatePanel from the parent page, which temporarily resolved the issue. However, the ultimate goal was to have Update Panels implemented in both the User Control and the Parent page simultaneously.