Hi,
Am writing a server control which contains a repeater control.
I followed the code outlined by Ra****@discussi ons.microsoft.c om (many
thanks)
on the following thread:
http://groups.google.com/groups?hl=e...oogle%2BSearch
I wish to extend the InstantiateIn code to include a button in the
repeater that raises an event that the containing page will handle.
The problem I have is the containing page doesn't 'see' the event
raised in my RepeaterTemplat e class. I guess I must handle the raised
button event in my main server control class and then re-raise it to
the containing page. The question is how do I do this??
The following shows the RepeaterTemplat e class that my server class
calls:
'============== =============== =============== =====
Class RepeaterTemplat e
Implements ITemplate
Private _templateType As ListItemType
Private _favouriteVisib le As Boolean
Private _btnAddToFavour ites As Button
'declare a public event
Public Event RepeaterButtonC licked As FavouritesEvent Handler
Sub New(ByVal type As ListItemType, _
ByVal favouriteVisibl e As Boolean)
_templateType = type
_favouriteVisib le = favouriteVisibl e
End Sub
Sub InstantiateIn(B yVal container As Control) Implements
ITemplate.Insta ntiateIn
Dim lc As LiteralControl
Dim hyp As HyperLink
Select Case _templateType
Case ListItemType.Se parator
lc = New LiteralControl( "<br>")
container.Contr ols.Add(lc)
Case ListItemType.It em
_btnAddToFavour ites = New Button
_btnAddToFavour ites.Visible = _favouriteVisib le
_btnAddToFavour ites.Attributes ("title") = "Add to your
InfoNet favourites"
_btnAddToFavour ites.Text = "+"
_btnAddToFavour ites.Font.Size = FontUnit.Larger
_btnAddToFavour ites.BorderStyl e = BorderStyle.Non e
_btnAddToFavour ites.BorderColo r =
System.Drawing. Color.Transpare nt
_btnAddToFavour ites.BackColor =
System.Drawing. Color.Transpare nt
_btnAddToFavour ites.Style.Add( "CURSOR", "hand")
AddHandler _btnAddToFavour ites.Click, AddressOf
btnAddToFavouri tes_Click
'add the button control to the repeater template
container.Contr ols.Add(_btnAdd ToFavourites)
'create a new hyperlink control
hyp = New HyperLink
AddHandler hyp.DataBinding , AddressOf
Hyperlink_DataB inding
'add the hyperlink control to the repeater template
container.Contr ols.Add(hyp)
End Select
End Sub
Public Overridable Sub btnAddToFavouri tes_Click(ByVal sender As
System.Object, ByVal e As System.EventArg s)
RaiseEvent RepeaterButtonC licked(Me, New FavouritesEvent Args2)
End Sub
Private Sub Hyperlink_DataB inding(ByVal sender As Object, ByVal e
As System.EventArg s)
Dim hyp As HyperLink
Dim container As RepeaterItem
hyp = CType(sender, HyperLink)
container = CType(hyp.Namin gContainer, RepeaterItem)
hyp.NavigateUrl = CType(DataBinde r.Eval(containe r.DataItem,
"PAGE_URL") , String)
hyp.Text = CType(DataBinde r.Eval(containe r.DataItem,
"PAGE_URL_TEXT" ), String)
End Sub
End Class
' Contains the code for the custom event data class
FavouritesEvent Args.
' Also defines the event handler for the AddToFavourites Clicked event.
Public Class FavouritesEvent Args
Inherits EventArgs
End Class
Public Delegate Sub FavouritesEvent Handler(ByVal sender As Object,
ByVal fe As FavouritesEvent Args)
'============== =============== ============
Any suggestions/code snippets would be most gratefully received!