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
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
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);
}
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
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>
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;
}
}