Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to force a postback 1

Status
Not open for further replies.

ASPnetNovice

Programmer
Apr 28, 2005
19
US
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?
 
Might try removing them on Page_Prerender after you have used their click events.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top