Programmatically created web user control events

J

Jonas

I'v made a web user control that I use in one of my .aspx pages. This
user control is dynamically loaded a number of times depending on the
content of a ArrayList(stored in the session) containing DataSets.
Each DataSetscontains the necessary information required to fill the
user control with data. In each usercontrol there is a delete-button,
that when clicked will remove a DataSetsentry in the previously
mentioned ArryList. This will cause the aspx-page on Post Back to load
one less usercontrol.

The question: How shall I write the Click event for the
"delete-button" so that my aspx-page renders with one less user
Control on PostBack?
Because the user controls are programmatically loaded I have to load
them at every post Back, In what event should I do that?

With kind regards, Jonas
 
L

Lucas Tam

(e-mail address removed) (Jonas) wrote in @posting.google.com:
The question: How shall I write the Click event for the
"delete-button" so that my aspx-page renders with one less user
Control on PostBack?
Because the user controls are programmatically loaded I have to load
them at every post Back, In what event should I do that?

Look at the IPostBackEventHandler interface. This interface allows you
to process postback data BEFORE loading of the controls occurs.

Here's some code:


Public Class TestButton
Inherits Control
Implements IPostBackEventHandler
Implements INamingContainer

Dim sText As String

Public Overloads Sub RaisePostBackEvent(ByVal eventArgument As
String) Implements IPostBackEventHandler.RaisePostBackEvent
If eventArgument = "OK" Then
sText = "Event Argument OK"
Else
sText = "No Argument"
End If
End Sub

Protected Overrides Sub CreateChildControls()
Dim hlLink As HyperLink = New HyperLink()
hlLink.ID = Me.UniqueID
hlLink.Text = "ExecuteLink " & sText

hlLink.NavigateUrl = Page.GetPostBackClientHyperlink(hlLink,
"OK")
Me.Controls.Add(hlLink)
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top