C# ASP.net CS1061 部署时出现编译错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1198347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.net CS1061 Compilation Error on deployment
提问by Jan W.
I'm having a bit of a pain here and I just can't figure out what's wrong.
我在这里有点痛苦,我无法弄清楚出了什么问题。
I have an ASP.net project which I deployed on a server. At first everything seemed allright, no Errors whatsoever. However, as a last adition I wanted to add a search function to a fairly large list so I added the following syntax to my mark-up:
我有一个部署在服务器上的 ASP.net 项目。起初一切似乎都很好,没有任何错误。但是,作为最后一个补充,我想将搜索功能添加到一个相当大的列表中,因此我将以下语法添加到我的标记中:
<td>
Search Server:
<asp:TextBox ID="txtSearch" runat="server" />
<asp:Button ID="btnLookup" runat="server" OnClick="btnLookup_Clicked" Text="Search" />
<asp:Label ID="lblFeedback" runat="server" />
</td>
and the following in code behind:
以及后面的代码中的以下内容:
protected void btnLookup_Clicked(object sender, EventArgs e)
{
lblFeedback.Text = "";
Session["IsSearch"] = true;
LoadServerList();
}
When I run this locally it works just fine as I expect. HOWEVER!
当我在本地运行它时,它按我的预期工作得很好。然而!
When I copy these files to the server I get a compilation error:
当我将这些文件复制到服务器时,出现编译错误:
Compiler Error Message: CS1061: ' ASP.ntservice_ reports_ reports_ serverlist_ manage_ aspx ' does not contain a definition for 'btnLookup_ Clicked' and no extension method 'btnLookup_ Clicked' accepting a first argument of type 'ASP.ntservice_ reports_ reports_ serverlist_ manage_ aspx' could be found (are you missing a using directive or an assembly reference?)
编译器错误消息:CS1061:“ASP.ntservice_reports_reports_serverlist_manage_aspx”不包含“btnLookup_Clicked”的定义,并且没有接受“ASP.ntservice_reports_reports_serverlist_manage_aspx”类型的第一个参数的扩展方法“btnLookup_Clicked”可以找到(您是否缺少 using 指令或程序集引用?)
it says there is nothing that handles my Clicked event although it does work when I run it through Visual studio.
它说没有任何东西可以处理我的 Clicked 事件,尽管当我通过 Visual Studio 运行它时它确实有效。
any ideas?
有任何想法吗?
EDIT: What I tried myself is
编辑:我自己尝试的是
- renaming button
- deleting and readding the button
- add through designer
- renaming click event
- removing the event from markup allows normal execution ... :/
- 重命名按钮
- 删除和读取按钮
- 通过设计器添加
- 重命名点击事件
- 从标记中删除事件允许正常执行...:/
采纳答案by Randy supports Monica
Is your project a web site or a web application? I would guess that it's a web application project and that perhaps you don't have the latest DLL deployed from the bin folder. Check the versions between your machine and the server to verify that they are the same.
您的项目是网站还是网络应用程序?我猜它是一个 Web 应用程序项目,也许您没有从 bin 文件夹部署最新的 DLL。检查您的机器和服务器之间的版本以验证它们是否相同。
回答by Arsen Mkrtchyan
Do you set
你设置了吗
<%@ Page ... Language="C#" CodeBehind="... .aspx.cs" Inherits="..." .../>
in your page directive correctly?
在您的页面指令中正确吗?
回答by jeroenh
Did you deploy the dll?
你部署了dll吗?
回答by Alex
This should fix it if you did everything else right:
如果您做对了其他所有事情,这应该可以解决它:
Try to make an entirely new click event (using the split view, just to be sure you get the method signature right.)
尝试创建一个全新的点击事件(使用拆分视图,以确保您获得了正确的方法签名。)
Then copy your code from your previous clicked event into the newly created event, copy the new event's method name to your original button and see if it works.
然后将您之前单击的事件中的代码复制到新创建的事件中,将新事件的方法名称复制到您的原始按钮并查看它是否有效。
回答by S M Kamran
Try renaming the event handler to some thing OnClick="buttonLookup_Clicked"... and changing the event handler signature to match it.
尝试将事件处理程序重命名为 OnClick="buttonLookup_Clicked"... 并更改事件处理程序签名以匹配它。
回答by sys_debug
having the same issue myself, I made the method public so that removed the compiler error, then followed that with including everything within
我自己也遇到了同样的问题,我将该方法公开,以便消除编译器错误,然后将所有内容包含在内
<form runat="server">
.....
<asp:Button id... OnClick="MethodName"/>
</form>
Hope this helps
希望这可以帮助
回答by Leandro Sardinha
I think this error is generated when you change an object Name, ex. Text1 -? txtSerialNo I had the same problem but I could fix it. Here is the solution: Go to Split Mode, click on the textbox/object, in the code remove the line
我认为当您更改对象名称时会生成此错误,例如。文本1 -?txtSerialNo 我有同样的问题,但我可以解决它。这是解决方案:转到拆分模式,单击文本框/对象,在代码中删除该行
[**ontextchanged="txtSerialNo_TextChanged"**]
From:
从:
[<asp:TextBox ID="txtSerialNo" runat="server"
ontextchanged="txtSerialNo_TextChanged"></asp:TextBox> //remove this line]
To:
到:
[<asp:TextBox ID="txtSerialNo" runat="server"</asp:TextBox>]
I hope it works for you. Bless you.
我希望这个对你有用。祝福你。
回答by southsidesmoka
Make the events your onclick events point to public.
使您的 onclick 事件指向公共事件。
回答by Tom Knowlton
This can happen if the event is signed-up for programmatically AND also in the markup (via the properties)
如果事件以编程方式注册并且也在标记中(通过属性),则可能会发生这种情况
回答by wafe
I experienced same problem. And I made the event handler method public, problem solved!
我遇到了同样的问题。我公开了事件处理程序方法,问题解决了!
Thanks!
谢谢!