Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In response to your second update,</p> <p>I had this exact problem, and I believe it has to do with the fact that you are adding a dynamic control to your page inside of the UpdatePanel.</p> <p>There may be a better way to do it out there, as I am certainly no ASP.NET expert, but I was able to solve this problem on my own by adding the control in a div that was hidden using CSS -before- it was needed, and then auto-incrementing the "dummy" control's ID so there are no conflicts, and I can keep adding as many as I want. That way, when the UpdatePanel is triggered it fully recognizes the controls and their contents, excepting the hidden ones of course.</p> <p>I am using XSL to transform my XML into a dynamic page that includes ASP.NET controls, so essentially I did the following:</p> <pre><code>&lt;div class="hide"&gt; &lt;asp:FileUpload CssClass="upload" identity="addVersion_{@id}_{count(draft) + 1}" runat="server" /&gt; &lt;asp:Button Text="Add File" identity="addVersionBtn_{@id}_{count(draft) + 1}" fileControlIdentity="addVersion_{@id}_{count(draft) + 1}" action="addVersion" runat="server" /&gt; &lt;/div&gt; </code></pre> <hr> <p>And then in the code-behind:</p> <pre><code>Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init //Code to generate the data (stripped out because it is generated in a different manner than the original poster) //Add events for all of the new-found controls depending on their type recursiveAddEvents(nameOfPlaceHolder.Controls) End Sub //Add events for all of the new-found controls depending on their type Sub recursiveAddEvents(ByRef controls As ControlCollection) For Each con As Control In controls If con.Controls.Count &gt; 0 Then recursiveAddEvents(con.Controls) End If //Try to cast the control to different data types Dim btn As Button = TryCast(con, Button) Dim file As FileUpload = TryCast(con, FileUpload) //Test to see which type the control was and apply the actions to it If Not btn Is Nothing Then //Assign the correct click events If btn.Attributes.Item("action") = "addVersion" Then AddHandler btn.Click, AddressOf addDraftVersion btn.ID = btn.Attributes.Item("identity") //Register the control with the ScriptManager ScriptManager.GetCurrent(Page).RegisterPostBackControl(btn) End If ElseIf Not file Is Nothing Then //Assign the correct click events file.ID = file.Attributes.Item("identity") End If Next End Sub Protected Sub addDraftVersion(ByVal sender As Button, ByVal e As EventArgs) Dim fileName as String = sender.Attributes("title").Replace(" ", "_") &amp; "_D" &amp; info("draftID") &amp; "_V" &amp; info("versionID") Dim inputControl As FileUpload = TryCast(trackPH.FindControl(sender.Attributes("fileControlIdentity")), FileUpload) If inputControl Is Nothing Then Exit Sub End If //Do whatever need to be done //Trigger UpdatePanel(s) nameOfUpdatePanel.Update() End Sub </code></pre> <hr> <p>I stripped out a lot of the code, but it should still get the general idea across :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload