views:

39

answers:

1

Hey, I need to send a byte array from javascript into a c# page method. The int and string variables work fine, but when I step through the c# code, the "object" which was the byte array is null, even though I checked to see if it had a value in JS.

     var byteArrayObj = GetBinaryDataFromFile(filePath);

     var tranAttachmentName = filePath.replace(/^.*\\/, '');
     PageMethods.AddFileToTran(tranId, tranAttachmentName, byteArrayObj, RefreshPage, onTimeout, onError);


     function GetBinaryDataFromFile(strFileName)
     {
         var streamObj = new ActiveXObject("ADODB.Stream");
         streamObj.Type = 1;
         streamObj.Open();
         streamObj.LoadFromFile(strFileName);
         var ByteArray = streamObj.Read();
         streamObj.Close();


         return(ByteArray);
     }  

c# code :

    [System.Web.Services.WebMethod]
    public bool AddFileToTran(int tranId, string tranAttachmentName, object byteArrayObj)
    {
        DBConnector dbConnectorObj = new DBConnector("cnnDataTracking");
        try
        { ........

The object byteArrayObj comes in null.

A: 

It turns out using the postback was the way to go on this. It didn't need to be asynchronous anyway. Thanks for the comments.

Kyle J V