New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Dynamically change the PostbackTriggers collection of the AsyncUpload

How To

Change the PostbackTriggers collection dynamically. For example, when the validation on the server passes, the control that fired the postback should become a PostbackTrigger for the AsyncUpload 

Solutions

The PostbackTriggers collection can be modified in the Page_Init event of the page lifecycle. That would allow adding certain controls to the PostbackTriggers collection based on hidden field values or some other custom logic.

The ViewState might overwrite your settings from the Page_Init, so it is advisable to setEnableViewState="false"to the AsyncUpload control.

Here is an example that adds the button that triggered a postback as a PostbackTrigger if the value of a hidden field is equal to "fixTriggers":

<asp:HiddenField runat="server" ID="shouldSave" />
function updateHiddenField() {
        var hidden = document.getElementById("<%= shouldSave.UniqueID %>");
        hidden.value = "fixTriggers";
}
protected void Page_Init(object sender, EventArgs e)
{
    if (Request[shouldSave.UniqueID] != null && Request[shouldSave.UniqueID].ToString() == "fixTriggers")
    {
        RadAsyncUpload1.PostbackTriggers = new string[] { "RadButton1" };
    }
    else
    {
        // persist the files on all postbacks
        RadAsyncUpload1.PostbackTriggers = new string[] { "" };
    }
}

protected void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
{
    shouldSave.Value = "";
}

Here are some resources that can help to get the ID of the control that triggered the postback:

In this article