This is a migrated thread and some comments may be shown as answers.

ComboBox not detected uploadFiles.cont

4 Answers 73 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Santos
Top achievements
Rank 1
Santos asked on 08 Nov 2012, 08:17 AM
Hello:

I have a RadComboBox in which I have to show one excel sheets to climb into a RadAsyncUpload.

I have a problem with this line:

if(Upload.UploadedFiles.Count > 0){}

If I access from a button, then Upload.uploadedFiles.count = 1 but I want it to be automatic, so I use the RadComboBox.ItemRequested. The problem is that then Upload.UploadedFiles.count = 0

What should I do to detect the file uploaded on RadAsyncUpload?

Thank you very much

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 08 Nov 2012, 09:08 AM
Hi Jorge,

In order to upload a file your application must perform a full page postback. On ItemRequested event the RadComboBox doesn't cause postback. Please take a look into this documentation for more information.

Hope this helps.

Regards,
Princy.
0
Santos
Top achievements
Rank 1
answered on 08 Nov 2012, 11:22 AM
Princy Sorry but I have not explained very well.
I put the code compliance for you to see what happens to me.

.aspx
<telerik:RadAsyncUpload 
                        ID="Upload" 
                        runat="server"
                        AllowedFileExtensions="xls,xlsx" 
                        MaxFileInputsCount="1" 
                        ViewStateMode="Enabled" 
                        Height="19px" 
                        Width="312px">
</telerik:RadAsyncUpload>

<telerik:RadComboBox ID="rcbHoja" runat="server"
                   EnableLoadOnDemand="True" 
                  onitemsrequested="rcbHoja_ItemsRequested">
</telerik:RadComboBox>


.aspx.cs

        #region rcbHoja
        protected void rcbHoja_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            if (Upload.UploadedFiles.Count > 0)
            {
                if (Upload.UploadedFiles.Count == 0)
                {
                    this.RadAjaxManager1.Alert("No existe Fichero");
                    return;
                }
                Upload.UploadedFiles[0].SaveAs(Server.MapPath("~/" + Upload.UploadedFiles[0].FileName));


                LeerHojas();
                this.rcbHoja.DataBind();
            }
        }

        public void LeerHojas()
        {
            // Leer el nombre de las hojas del fichero excel
            string Cadena = "Provider=Microsoft.ACE.Oledb.12.0; data source=" + Server.MapPath("~/" + Upload.UploadedFiles[0].FileName) + "; Extended properties=Excel 12.0;";
            OleDbConnection Conexion = new OleDbConnection();
            OleDbCommand Comand = new OleDbCommand();
            OleDbDataAdapter Da = new OleDbDataAdapter();
            DataTable Tabla = new DataTable();


            try
            {
                RadComboBoxItem Item;


                Conexion.ConnectionString = Cadena;
                Conexion.Open();
                Tabla.Clear();
                this.rcbHoja.Items.Clear();
                Tabla = Conexion.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);


                if (Tabla != null)
                {
                    foreach (DataRow fila in Tabla.Rows)
                    {
                        Item = new RadComboBoxItem();
                        Item.Value = fila["TABLE_NAME"].ToString();
                        Item.Text = fila["TABLE_NAME"].ToString();
                        this.rcbHoja.Items.Add(Item);
                    }
                }
            }
            catch (OleDbException ex)
            {
                if (ex.InnerException == null)
                {
                    this.RadAjaxManager1.Alert(ex.Message);
                }
                else
                {
                    this.RadAjaxManager1.Alert(ex.Message + " [" + ex.InnerException.Message + "] ");
                }
            }
            finally
            {
                Conexion.Close();
            }
        }

The problem is that the code within the ItemRequest this only works if I run it from a button and I want it to be automatic
if I run it from the ItemRequest upload.uploadedFiles = 0
if I run it from a button upload.uploadedFiles = 1
0
Plamen
Telerik team
answered on 12 Nov 2012, 10:02 AM
Hi Jorge,

 
The behavior you are observing is expected because as Princy pointed- RadAsyncUpload  stores the files  in a temporary location until a postback occurs. On ItemRequested event the RadComboBox doesn't cause postback and that is why the count of the uploaded files is zero.

Hope this will explain the issue.

Kind regards,
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Santos
Top achievements
Rank 1
answered on 12 Nov 2012, 10:08 AM
Hi:

In the end, when I upload a file I do not feel:

                    <telerik:RadAsyncUpload 
                        ID="Upload"
                        runat="server"
                        AllowedFileExtensions="xls,xlsx" 
                        MaxFileInputsCount="1"
                        ViewStateMode="Enabled"
                        Height="19px"
                        Width="312px"
                        onclientfileuploaded="Upload_PostBack">
                    </telerik:RadAsyncUpload>

function Upload_PostBack() {
          $find("<%=RadAjaxManager1.ClientID %>").ajaxRequest("FileUploaded");
        }


        protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            if (e.Argument == "FileUploaded")
            {
               //Here the code to execute after the postback
            }
        }

Thanks for your help
Tags
ComboBox
Asked by
Santos
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Santos
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or