ComboBox not detected uploadFiles.cont

5 posts, 1 answers
  1. Santos
    Santos avatar
    13 posts
    Member since:
    Nov 2012

    Posted 08 Nov 2012 Link to this post

    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

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Nov 2012 Link to this post

    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.
  3. Santos
    Santos avatar
    13 posts
    Member since:
    Nov 2012

    Posted 08 Nov 2012 Link to this post

    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
  4. Plamen
    Admin
    Plamen avatar
    3047 posts

    Posted 12 Nov 2012 Link to this post

    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.
  5. Santos
    Santos avatar
    13 posts
    Member since:
    Nov 2012

    Posted 12 Nov 2012 Link to this post

    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
Back to Top