find dynamic added panel

i'm adding a panel like this to my web application:

For i = 1 To amountOfRechnungspositionen + 1 
  Dim pnlPositon As Panel = New Panel
  pnlPositon.ID = "pnlPositon" & i
  pnlRechungsposition.Controls.Add(pnlPositon)
   ... 
Next

Now if i onclick a button, i want to delete this panel. This is my code.

Private Sub imgDelRechnungsPosition_Click(sender As Object, e As ImageClickEventArgs) Handles imgDelRechnungsPosition.Click

    amountOfRechnungspositionen = Convert.ToInt32(hfAmountofRechnungspositionen.Value)

    Dim fcpnlPositon As Panel = DirectCast(pnlRechungsposition.FindControl("placeholderID$pnlPositon" + amountOfRechnungspositionen.ToString()), Panel)
    fcpnlPositon.Dispose()

    hfAmountofRechnungspositionen.Value = Convert.ToString(amountOfRechnungspositionen - 1)

End Sub

But fcpnlPositon is Nothing. Waht i'm doing wrong?

Thank u, for reading.


ANSWERS:


Try using:

CType(pnlRechungsposition.FindControl("pnlPositon" + 
           amountOfRechnungspositionen.ToString()), Panel)

The placeholder text is only for client-side markup and thus you want to use the direct ID property.



 MORE:


 ? Dynamically add to the first collection in a nested collection VBA
 ? Add buttons Dynamically at Runtime
 ? Add buttons Dynamically at Runtime
 ? Add buttons Dynamically at Runtime
 ? Position HTML button dynamically in C#
 ? How do I create 5 buttons and assign individual click events dynamically?
 ? How do I remove combo box dynamically in C# by pressing a button in runtime?
 ? How to add buttons dynamically to my form?
 ? Getting Dynamic (Runtime) Buttons in WP7 to Associate with Objects
 ? How to dynamically add buttons to ListBox - WFP - C#