ASP.default_aspx' does not contain a definitio

2020-02-16 03:39发布

问题:

I created a gridview using Telerik asp.net/ajax controls and when I run the app locally the grid works fine but when pushed to my server I get the same error for all of my methods:

ASP.default_aspx' does not contain a definition for 'IssuesGrid_OnItemUpdated' and no extension method 'IssuesGrid_OnItemUpdated' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?)

I have tried deleting the reference in the grid and creating it again and letting VS create the method and then it'll work until I do that for all of the methods throwing the error and then it starts all over again.

Here is the aspx page:

   <telerik:RadGrid ID="Issues" runat="server" CellSpacing="0" DataSourceID="GridSource" GridLines="None" Skin="Metro"
                AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True" OnItemDataBound="Issues_OnItemDataBound" 
                PageSize="30" EnableLinqExpressions="false" EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true"
                AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
                OnItemUpdated="Issues_OnItemUpdated" OnItemInserted="Issues_OnItemInserted" OnItemDeleted="Issues_OnItemDeleted"
                OnItemCommand="Issues_OnItemCommand"
                AutoGenerateColumns="False" ShowStatusBar="True" HorizontalAlign="Center" Height="900px">

And here are my methods in my cs file:

  protected void Issues_OnItemUpdated(object sender, GridUpdatedEventArgs e)
        {
            if (e.Exception != null)
            {
                e.KeepInEditMode = true;
                e.ExceptionHandled = true;
                DisplayMessage(true, "Defect " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " cannot be updated. Reason: " + e.Exception.Message);
            }
            else
            {
                DisplayMessage(false, "Defect " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " updated");
            }
        }

        protected void Issues_OnItemInserted(object source, GridInsertedEventArgs e)
        {
            if (e.Exception != null)
            {
                e.ExceptionHandled = true;
                e.KeepInInsertMode = true;
                DisplayMessage(true, "Defect cannot be inserted. Reason: " + e.Exception.Message);
            }
            else
            {
                DisplayMessage(false, "Defect inserted!");
            }
        }

        protected void Issues_OnItemDeleted(object source, GridDeletedEventArgs e)
        {
            if (e.Exception != null)
            {
                e.ExceptionHandled = true;
                DisplayMessage(true, "Defect " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " cannot be deleted. Reason: " + e.Exception.Message);
            }
            else
            {
                DisplayMessage(false, "Defect " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " deleted");
            }
        }


        protected void Issues_OnItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.InitInsertCommandName) //"Add new" button clicked
            {
                var editColumn = (GridEditCommandColumn)Issues.MasterTableView.GetColumn("EditCommandColumn");
                editColumn.Visible = false;
            }
            else if (e.CommandName == RadGrid.RebindGridCommandName && e.Item.OwnerTableView.IsItemInserted)
            {
                e.Canceled = true;
            }
            else
            {
                var editColumn = (GridEditCommandColumn)Issues.MasterTableView.GetColumn("EditCommandColumn");
                if (!editColumn.Visible)
                    editColumn.Visible = true;
            }
        }

What's weird is I have an ondatabound method that is just fine and worked before any of these problems started and continues to work. I tried changing the 'object sender' to 'object source' but still a no go.

Here is the OnDataBound event:

   protected void Issues_OnItemDataBound(object source, GridItemEventArgs e)
            {
                var gridDataItem = e.Item as GridDataItem;
                if (gridDataItem != null)
                {
                    var item = gridDataItem;

                    //Tooltips
                    if (!item.IsInEditMode)
                    {
                        var cell = item["Description"];
                        if (cell.Text.Length > 40)
                        {
                            var originaltext = cell.Text;
                            cell.Text = cell.Text.Remove(40) + "...";
                            cell.ToolTip = originaltext;
                        }
                    }
                }
}

Any help on what I am doing wrong would be great!

回答1:

Your code-behind (the .cs file) gets compiled into a dll when you deploy. Ensure that when you publish, these dll files are being copied over as well. This also means your published project should not have any .cs or .designer.cs files.