Showing posts with label containing. Show all posts
Showing posts with label containing. Show all posts

Wednesday, March 21, 2012

Trouble trying to use PostbackTrigger with FileUpload in UpdatePanel

Scenario: I have 2 UpdatePanels, 1 containing a GridView (master) and the other containing a DetailsView (child). The DetailsView has an AsyncPostBackTrigger for the GridView's SelectedIndexChanged event. I use a CommandField with ShowEditButton in the DetailsView. The DetailsView is in Edit mode by default. One of the fields in the DetailsView contains a FileUpload. In the ItemCreated event, I register the auto generated "Update" LinkButton as a PostBackControl. I have also tried adding a PostBackTrigger to the UpdatePanel, but neither attempt results in the FileUpload.HasFile property being true.

1Protected Sub dv_ItemCreated(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles dv.ItemCreated2Dim linkAs LinkButton =Nothing3 Dim triggerAs PostBackTrigger =Nothing4 If Not dv.FooterRowIs Nothing Then5 Dim commandRowIndexAs Integer = 06Dim commandRowAs DetailsViewRow = dv.Rows(commandRowIndex)7Dim cellAs DataControlFieldCell =CType(commandRow.Controls(0), DataControlFieldCell)8For Each ctlAs ControlIn cell.Controls9If TypeOf ctlIs LinkButtonThen10 link =CType(ctl, LinkButton)11Else : link =Nothing12 End If13 If Not linkIs Nothing Then14 If link.CommandName.Equals("update", StringComparison.CurrentCultureIgnoreCase)Then15'trigger = New PostBackTrigger16 'trigger.ControlID = link.ClientID17 'upDV.Triggers.Add(trigger)18 ScriptManager.GetCurrent(Me).RegisterPostBackControl(CType(link, Control))19End If20 End If21 Next22 End If23 End Sub
The page does do a full postback when the Update button is hit, so at least that works. I'm assuming that HasFile is false for the first Update because the Update button is not registered with the ScriptManager when the page is loaded. After an update, page is loaded with the control registered as a PostBackControl, thus making subsequent updates work fine. Assuming that this is correct, is there anyway to do this? My reasoning in this assumption is that if I select a row in the GridView by default such that when the DetailsView is first loaded into the page, it has a record as opposed to the EmptyDataText being shown, everything works as expected. Is there a way to use this functionality without having a record in DetailsView before the user actually selects a record?

Kind of funny that this works at all. The PostBackTrigger is supposedly not capable of being added programatically based onthe docs.

Ryan Pedersen
MCP


According to the documentation for AJAX the FileUpload control is not supported.

There are several work around available on this forum.