按下按钮时程序不工作asp.net Web Form 3.5

问题描述 投票:0回答:0

我有以下代码:

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);
       //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}

如果

FillData
功能被注释掉并且所有按钮都响应它们的事件,则此代码可以正常工作。

但是一旦我取消注释

FillData
方法,初始加载工作正常,函数代码如下(数组的所有行都有完全空字段):

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);
}

但是所有的按钮都停止工作了。在谷歌中我得到一个错误:

无法连接到该站点位于 http://localhost:60226/Request.aspx 的网页可能暂时不可用,或者可能已永久移动到新网址。
ERR_CONNECTION_ABORTED

我无法调试代码,也没有触发任何按钮事件。

我有另一个页面,它在结构上与这个页面相似并且可以工作——唯一的区别是我得到了不同的数据。请告诉我我的数据究竟有什么问题,即使使用调试器我也无法捕获错误?

请帮我解决这个问题

c# button gridview asp.net-3.5
© www.soinside.com 2019 - 2024. All rights reserved.