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

Upload in dynamically loaded user control

6 Answers 176 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Dave Miller
Top achievements
Rank 2
Dave Miller asked on 15 May 2008, 12:57 PM
Is this possible? I have have disabled ajax on the call but still have UploadedFiles.Count = 0.

Is this because the usercontrol is being reloaded on each postback and if so is there a workaround?

Thanks,
Dave

6 Answers, 1 is accepted

Sort by
0
Erjan Gavalji
Telerik team
answered on 15 May 2008, 02:29 PM
Hi Dave,

RadUpload should not cause problems when working within a user control. Please, find attached a small setup I just prepared. Can you check it and let me know if I am missing something?

Kind regards,
Erjan Gavalji
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Dave Miller
Top achievements
Rank 2
answered on 15 May 2008, 03:03 PM
Erjan,

Thanks for the quick response. The dynamically loaded user control contains a grid which is basically the same as in the example at http://www.telerik.com/demos/aspnet/prometheus/Controls/Examples/Integration/RadUploadInAjaxifiedGrid/DefaultCS.aspx?product=grid

using the modified code below returns "There are 0 uploaded files! "

protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
        {
            ////if (IsValid)
            ////{
            RadUpload uploader = e.Item.FindControl("RadUpload1") as RadUpload;
            TextBox imageDescription = e.Item.FindControl("txbDescription") as TextBox;
            TextBox imageName = e.Item.FindControl("txbName") as TextBox;
            RadComboBox author = e.Item.FindControl("AuthorImagesList") as RadComboBox;

            //    UploadedFile imageFile = null;
            //    // if (uploader.InvalidFiles.Count == 0)
            //    //{

            //    //if (uploader.UploadedFiles.Count > 0)
            //    //{
            //        imageFile = uploader.UploadedFiles[0];
            //        InsertDb(imageFile, imageDescription.Text, imageName.Text, Int32.Parse(author.SelectedValue));
                   
            //    //}

            //    //}

            lblResult.Text = string.Format("There are {0} uploaded files!", uploader.UploadedFiles.Count);
        }



0
Erjan Gavalji
Telerik team
answered on 15 May 2008, 03:56 PM
Hi Dave,

The problem comes, because file uploads cannot be done via Ajax. What you can do is disable the Ajax call for the Update button of RadGrid.

Let me know if that helps.

Kind regards,
Erjan Gavalji
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Dave Miller
Top achievements
Rank 2
answered on 15 May 2008, 04:21 PM

Erjan,

As I stated in my initial post I have disabed ajax in the call. The code is below and I have double checked it and it is working fine but I am still losing the upload files.

   <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">      
     <script type="text/javascript">
        function mngRequestStarted(ajaxManager, eventArgs)
        {
         if(eventArgs.EventTarget.indexOf("PerformInsertButton") != -1)
         {
            eventArgs.EnableAjax = false;
         }
        }
     </script>

     </telerik:RadCodeBlock>

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <ClientEvents OnRequestStart="mngRequestStarted" />
    </telerik:RadAjaxManager>

0
Dave Miller
Top achievements
Rank 2
answered on 15 May 2008, 08:42 PM
Erjan,

Wanted to let you know if I put the ascx code in a aspx page it works fine.

Below is the code I am using to dynamically add the user control in which the upload is not working. Any Ideas would be greatly appreciated

Thanks,
Dave


protected void Page_Load(object sender, EventArgs e)
        {

            if (this.CurrentControl != null)
            {
                LoadUserControl(CurrentControl);
            }

  if (!Page.IsPostBack)
         {
  string strControl = "somecontrolname";
  LoadUserControl(strControl);
  }

 }

 
public void LoadUserControl(string controlName)
        {
            if (CurrentControl != null)
            {
                Control previousControl = ctrlPanel.FindControl(CurrentControl.Split('.')[0]);
                if (!Object.Equals(previousControl, null))
                {
                    this.ctrlPanel.Controls.Remove(previousControl);
                }
            }
            string userControlID = controlName.Split('.')[0];
            Control targetControl = ctrlPanel.FindControl(userControlID);
            if (Object.Equals(targetControl, null))
            {
                UserControl userControl = (UserControl)this.LoadControl(controlName);
                //slashes and tildes are forbidden
                //  ((CustomControl)userControl).ID = userControlID.Replace("/", "").Replace("~", "");
                ((CustomControl)userControl).ID = "customCntl";
                ((CustomControl)userControl).intControlID = 1;

  // CtrlPanel is a asp:panel

                this.ctrlPanel.Controls.Add(userControl);
                CurrentControl = controlName;
            }
        }

        private string CurrentControl
        {
            get
            {
                return (string)ViewState["LatestLoadedControlName"];
            }
            set
            {
                ViewState["LatestLoadedControlName"] = value;
            }
        }

0
Blaize
Top achievements
Rank 1
answered on 17 May 2008, 04:23 PM
Tags
Upload (Obsolete)
Asked by
Dave Miller
Top achievements
Rank 2
Answers by
Erjan Gavalji
Telerik team
Dave Miller
Top achievements
Rank 2
Blaize
Top achievements
Rank 1
Share this question
or