ASPnetNovice
Programmer
Hello,
I have the following situation
I create a button (and other controls) dynamically at runtime
And I have a mechanism to persist the button(and other controls) via session so that everytime a postback occurs the button gets recreated.
I am using an arraylist to store the button ( and other controls). When the button gets clicked , I want to destroy it so that it disappear from the form in a button click event:
------
Dim al As ArrayList = CType(Me.Session("DynamicControls"), ArrayList)
For Each item As ControlInfo In al
If item.ID = "cmdDeleteLast" Then
index2erasebt = al.IndexOf(item)
End If
Next
al.RemoveAt(index2erasebt)
------
For some reason I am able to make it go away but only after I click it twice. I think it has something to do with postback (or viewstate?)
I can get it to work by adding the following to the above event:
------
Server.Transfer("myPage.aspx", True)
------
Is there another - more direct way - to remove a control from a form?
I have the following situation
I create a button (and other controls) dynamically at runtime
And I have a mechanism to persist the button(and other controls) via session so that everytime a postback occurs the button gets recreated.
I am using an arraylist to store the button ( and other controls). When the button gets clicked , I want to destroy it so that it disappear from the form in a button click event:
------
Dim al As ArrayList = CType(Me.Session("DynamicControls"), ArrayList)
For Each item As ControlInfo In al
If item.ID = "cmdDeleteLast" Then
index2erasebt = al.IndexOf(item)
End If
Next
al.RemoveAt(index2erasebt)
------
For some reason I am able to make it go away but only after I click it twice. I think it has something to do with postback (or viewstate?)
I can get it to work by adding the following to the above event:
------
Server.Transfer("myPage.aspx", True)
------
Is there another - more direct way - to remove a control from a form?