C# '' 没有重载匹配委托 'System.EventHandler'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19392033/
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
No overload for '' matches delegate 'System.EventHandler'
提问by Fabio Corintiano
This code generate the error above, Im trying to do some method which sends a file to ftp server
这段代码产生了上面的错误,我试图做一些将文件发送到 ftp 服务器的方法
public void btnSend_Click(object sender, GridViewCommandEventArgs e)
{
msgerror = SP.StrSPBUS_DocClient(Convert.ToInt32(e.CommandArgument.ToString()));
if (msgerror.Equals("Sucess"))
{
String Files = SP.OUTSTR_NMDOCUMENT;
String Address = SP.OUTSTR_FTPCAM;
String User = SP.OUTSTR_FTPUSER;
String Pass = SP.OUTSTR_FTPPASS;
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(Address + "/" + Path.GetFileName(File));
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(User, Pass);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
var stream = File.OpenRead(Files);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
var reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
}
else
{
SP.StrImprimeMessage("Error!");
return;
}
}
and file .aspx this is the code of button
和文件 .aspx 这是按钮的代码
<tr class="tabelinner">
<td class="leftcell" valign="middle">
<asp:Button ID="btnSrend" runat="server" Text="Send" CssClass="ButtonLink" ValidationGroup="sending" CommandArgument="Sending" onclick="btnSend_Click" />
<br />
</td>
</tr>
回答by Hector Sanchez
The problem is with GridViewCommandEventArgs
should be just EventArgs
问题是GridViewCommandEventArgs
应该只是EventArgs
public void btnSend_Click(object sender, EventArgs e)
Edit:
编辑:
I see that in your code you use the Command Argument, so if you want to use that you should see this post
我看到在你的代码中你使用了命令参数,所以如果你想使用它,你应该看到这篇文章
Basically use onCommand
instead of onClick
or cast the sender to button to get the command argument, something like:
基本上使用onCommand
而不是onClick
或将发送者转换为按钮来获取命令参数,例如:
var argument = ((Button)sender).CommandArgument;
回答by Steve
The correct signature for a button click event is
按钮单击事件的正确签名是
public void btnSend_Click(object sender, EventArgs e)
but at this point you have a problem because the EventArgs instance passed has no knowledge of a property called e.CommandArgument
, so you need another way to use that value inside this event.
但是此时您遇到了问题,因为传递的 EventArgs 实例不知道名为 的属性e.CommandArgument
,因此您需要另一种方法在此事件中使用该值。