> Just for grins, I added a button. In this paricular scenario, the
> button does not make sense but assume I was adding labels and text
> boxes and allowed a user to submit information via the text boxes.
>
> How would you specify the on_click envent handler in this example?
Code snippets to help you along:
B = New ImageButton
With B
.AlternateText = "Delete"
.ImageUrl = "images/delete.gif"
' n is the index of this item in the basket
.ID = "B_" & n.ToString
AddHandler .Click, AddressOf DeleteEntry
End With
PL.Controls.Add(B)
Private Sub DeleteEntry(ByVal sender As Object, ByVal e As
System.web.UI.ImageClickEventArgs)
' retrieve the ID number to index into the basket
Dim n As Integer = CInt(Mid(CType(sender, ImageButton).ID, 3))
' remove corresponding entry
DirectCast(Session("basky"),
basketCentral).currentBasketItems.RemoveAt(n)
' throw away the controls as they have been created before this Sub is
called
' but with the deleted entry included
PL.Controls.Clear()
showBasketContent()
End Sub
(This is with AutoEventWireup="false" in the <%@ Page %> directive, so
remember to use "Handles", e.g.
Private Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs) Handles
MyBase.Load).
> How would we make sure the labels, textboxes and buttond survive a
> post back?
I just create it all again each time. I have a suspicion I'm doing something
out of order with my code (where I throw the controls away) because I create
the items in Page_Load but it was noisy in the office when I wrote it and it
works anyway, <mumble>, <mumble>, <cough> "if not page.ispostback" or
something needed.
HTH
Andrew
WhiskeyRomeo - 07 Dec 2007 16:15 GMT
Andrew,
Again thanks for the repsonse and the education. You have my vote for MVP.
Bill
> > Just for grins, I added a button. In this paricular scenario, the
> > button does not make sense but assume I was adding labels and text
[quoted text clipped - 45 lines]
>
> Andrew