【发布时间】:2018-12-06 14:48:16
【问题描述】:
我收到以下错误:
An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compile Error Message: CS1061: 'codebehind' does not contain a definition for 'btnSave_Click' and no extension method 'btnSave_Click' accepting a first argument of type 'codebehind' could be found (are you missing a using directive or an assembly reference?)
视图中的 ASP 按钮:
<asp:Button ID="btnSave" runat="server" Text="Save" CssClass="btn btn-success btn-md" Width="100px" OnClick="btnSave_Click" />
后面代码中的事件注册:
override protected void OnInit(EventArgs e)
{
btnSave.Click += new EventHandler(btnSave_Click);
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
OnClick 事件:
private void btnSave_Click(object sender, EventArgs e)
{
//foo
}
我尝试过的事情:
- 在视图和代码隐藏中重命名 onClick 事件
- 删除onClick,进入设计选项卡,双击按钮自动生成新事件
- 将自动事件连接从 false 更改为 true
相关问题供参考:
- Does not contain a definition for and no extension method accepting a first argument of type could be found
- Error CS1061 “...Does Not Contain Definition and No Extension Method...accepting a first argument of type ” could be found
- "a" Does not contain a definition for"b" and no extension method ' b ' accepting a first argument of type
如果您需要更多信息,请告诉我。
【问题讨论】:
-
您可以尝试两件事。 1. 确保类后面代码的命名空间是正确的。 2.尝试干净的解决方案,退出Visual Studio,重新打开VS并重建解决方案。
-
命名空间是正确的,我尝试清理并重新启动,但错误仍然存在。