ASP.default_aspx' does not contain a definition for 'IssuesGrid_OnItemUpdated' and no extension method 'IssuesGrid_OnItemUpdated'

巧了我就是萌 提交于 2019-11-30 09:52:30

问题


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.



来源:https://stackoverflow.com/questions/21787935/asp-default-aspx-does-not-contain-a-definition-for-issuesgrid-onitemupdated-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!