I have the following code:
protected void Page_Load(object sender, EventArgs e)
{
if (!Authorization.OK)
Response.Redirect("Authorization.aspx", true);
var operators = OperatorService.GetAllOperators();
var currentOperator = operators.FirstOrDefault(x => x.Login == Authorization.UserName);
if (currentOperator == null || currentOperator.Login == null)
Response.Redirect("Authorization.aspx", true);
var resultAllRequest = ADCatalogueService.GetAllRequests(currentOperator.FacultyName);
if (!Constants.Admins.Contains(currentOperator.FacultyName))
resultAllRequest = resultAllRequest.Where(x => x.Status == "inProgress").ToArray();
tabAdmin.Visible = Constants.Admins.Contains(currentOperator.FacultyName);
// FillData(resultAllRequest);
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
This code works fine if the FillData function is commented out and all buttons respond to their events.
BUT as soon as I uncomment the FillData method, the initial load works fine, the function code is below (all rows of the array have exactly null fields):
private void FillData(RequestAD[] requestAds)
{
var requestViewModels = new List<RequestViewModel>();
foreach (var requestAd in requestAds.OrderBy(x => x.LastName))
{
var requestViewModel = new RequestViewModel();
requestViewModel.SecondName = requestAd.SecondName;
requestViewModel.PhoneNumber = requestAd.PhoneNumber;
requestViewModel.Email = requestAd.Email;
requestViewModel.FacultyName = requestAd.FacultyName;
requestViewModel.LastName = requestAd.LastName;
requestViewModel.FirstName = requestAd.FirstName;
requestViewModel.ImageHtml = "<img src=\"data:image/jpeg;base64," + requestAd.Image + "\">";
requestViewModel.ButtonsField = "<div value=\"" + requestAd.Status + "\" class=\"buttonContainer\"><input class=\"id\" value=\"" + requestAd.Id + "\"></input><a class=\"tableBtn acceptBtn\" onclick=\"acceptRequest(this)\"></a><a class=\"tableBtn removeBtn\" onclick=\"removeRequest(this)\"></a></div>";
requestViewModels.Add(requestViewModel);
}
requestViewModels = requestViewModels
.Where(x =>
!string.IsNullOrEmpty(x.LastName)
&& !string.IsNullOrEmpty(x.FirstName)
&& !string.IsNullOrEmpty(x.SecondName)
&& !string.IsNullOrEmpty(x.FacultyName)
&& !string.IsNullOrEmpty(x.Email)
&& !string.IsNullOrEmpty(x.PhoneNumber))
.ToList();
GridView1.AutoGenerateColumns = false;
GridView1.Columns.Clear();
var columns = new CustomiseColumnModel[] {
new CustomiseColumnModel
{
ProperityName = "FullName",
DisplayName = "ПІБ"
},
new CustomiseColumnModel
{
ProperityName = "SecondName",
DisplayName = "Прізвище"
},
new CustomiseColumnModel
{
ProperityName = "FirstName",
DisplayName = "Ім`я"
},
new CustomiseColumnModel
{
ProperityName = "LastName",
DisplayName = "По-батькові"
},
new CustomiseColumnModel
{
ProperityName = "Email",
DisplayName = "Емаіл"
},
new CustomiseColumnModel
{
ProperityName = "PhoneNumber",
DisplayName = "Номер телефону"
},
new CustomiseColumnModel
{
ProperityName = "FacultyName",
DisplayName = "Факультет",
Width = 350
},
new CustomiseColumnModel
{
ProperityName = "ImageHtml",
DisplayName = "Photo",
Width = 350,
},
new CustomiseColumnModel
{
ProperityName = "ButtonsField",
DisplayName = "Дія",
Width = 100,
}
};
foreach (var column in columns)
{
CustomiseColumn(column);
}
GridView1.DataSource = requestViewModels;
GridView1.DataBind();
}
private void CustomiseColumn(CustomiseColumnModel columnModel)
{
BoundField column = new BoundField();
column.ItemStyle.BorderStyle = BorderStyle.Double;
if (columnModel.Width != null)
column.ItemStyle.Width = new Unit(columnModel.Width.Value);
column.DataField = columnModel.ProperityName;
if (columnModel.ProperityName == "ImageHtml" || columnModel.ProperityName == "ButtonsField")
column.HtmlEncode = false;
column.HeaderText = columnModel.DisplayName;
GridView1.Columns.Add(column);
}
But all the buttons stop working. And in Google I get an error:
No connection to the site The web page at http://localhost:60226/Request.aspx may be temporarily unavailable or may have been permanently moved to a new web address.
ERR_CONNECTION_ABORTED
I can't debug the code and no button event is fired.
I have another page that is structurally similar to this one and it works - the only difference is that I get different data. Please tell me what exactly could be wrong with my data that I can't catch the error even with a debugger?
Please help me solve this problem