Fabio Corintiano
Fabio Corintiano

Reputation: 31

No overload for '' matches delegate 'System.EventHandler'

This code generate the error above, Im trying to do some method which sends a file to ftp server

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

<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>

Upvotes: 3

Views: 22346

Answers (2)

Steve
Steve

Reputation: 216313

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.

Upvotes: 3

Hector Sanchez
Hector Sanchez

Reputation: 2317

The problem is with GridViewCommandEventArgs should be just 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:

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

Upvotes: 6

Related Questions