New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
How to Preserve Upload Configuration
Preserving UploadConfiguration
Initially the default value of PersistConfiguration property is false. However, by setting it to true, the UploadConfiguration property can be persisted through postbacks via ControlState(only in case the UploadConfiguration property is not null).
The ControlState property allows you to persist property information that is specific to a control and cannot be turned off like the ViewState property for instance. Use the control state only for small amount of critical data that is essential for the control across postbacks. The control state should not be used as an alternative to view state.
If you use this, see Security - Custom Metadata.
The following code snippets demonstrate how it can be used:
C#
protected void Page_Load(object sender, EventArgs e)
{
//It is possible to set PersistConfiguration propety from the markup and form the code behind
RadAsyncUpload1.PersistConfiguration = true;
Button1.Click += new EventHandler(Button1_Click);
if (!IsPostBack)
{
SampleAsyncUploadConfiguration config =
RadAsyncUpload1.CreateDefaultUploadConfiguration<SampleAsyncUploadConfiguration>();
config.UserID = 1;
config.UserName = "TelerikUser";
RadAsyncUpload1.UploadConfiguration = config;
}
}
void Button1_Click(object sender, EventArgs e)
{
var uploadConfiguration = (SampleAsyncUploadConfiguration)RadAsyncUpload1.UploadConfiguration;
Label1.Text = uploadConfiguration.UserID.ToString();
Label2.Text = uploadConfiguration.UserName;
}
...
[Serializable]
public class SampleAsyncUploadConfiguration : IAsyncUploadConfiguration
{
public int UserID { get; set; }
public string UserName { get; set; }
public string TargetFolder { get; set; }
public string TempTargetFolder { get; set; }
public int MaxFileSize { get; set; }
public TimeSpan TimeToLive { get; set; }
}