没有重载''匹配委托'System.EventHandler'

时间:2013-10-15 22:15:09

标签: c# .net

此代码生成上述错误,我试图做一些将文件发送到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;
    }
}

和文件.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>

2 个答案:

答案 0 :(得分:6)

问题在于GridViewCommandEventArgs应该只是EventArgs

public void btnSend_Click(object sender, EventArgs e)

修改

我在你的代码中看到你使用Command Argument,所以如果你想使用它,你应该看到this post

基本上使用onCommand代替onClick或将发送者强制转换为按钮以获取命令参数,例如:

var argument = ((Button)sender).CommandArgument;

答案 1 :(得分:3)

按钮点击事件的正确签名是

public void btnSend_Click(object sender, EventArgs e)

但此时您遇到了问题,因为传递的EventArgs实例不知道名为e.CommandArgument的属性,因此您需要另一种方法在此事件中使用该值。