3

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>
Black Sheep
  • 6,604
  • 7
  • 30
  • 51
Fabio Corintiano
  • 31
  • 1
  • 1
  • 2
  • since you are new to SO, dont forget to upvote that helpful answers to you, and check the accepted answer as the one that completely answer your question – Hector Sanchez Oct 15 '13 at 22:43

2 Answers2

6

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;
Community
  • 1
  • 1
Hector Sanchez
  • 2,297
  • 4
  • 26
  • 39
  • You should edit your question and post that answer into it or ask a new question for that, but of course you are getting an exception, `CommandArgument="Sending"`, that word is an string, how do you intent that to be int? What are you trying to do? Or what is supposed to be send to the `StrSPBUS_DocClient` method ? – Hector Sanchez Oct 16 '13 at 14:02
3

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.

Steve
  • 213,761
  • 22
  • 232
  • 286