jag sitter och tragglar med en composite control som innehåller 2 textboxar, en knapp, en rangevalidator och en labelComposite control i repeater
Syftet med den är att visa en köp-knapp + ruta för antal i en webshop
om lagerstausen är 0 så skall istället labeln visas
frågan är då hur jag hanterar knapptryckningen i kontrollen så att varan i vald "rad" i min repeater väljs
control.vb
Public Class BuyPanel : Inherits Control : Implements INamingContainer
Public Event Click(ByVal Sender As Object, ByVal E As System.EventArgs)
Private _Quantity As Integer
Private _RealStock As Integer
Private _ProdID As Integer
Public Property ProdID() As Integer
Get
'Dim Ctrl As TextBox = Controls(0)
'Me.EnsureChildControls()
' Return Int32.Parse(Ctrl.Text)
Return _ProdID
End Get
Set(ByVal value As Integer)
' Dim Ctrl As TextBox = Controls(0)
' Me.EnsureChildControls()
' Ctrl.Text = value.ToString()
_ProdID = value
End Set
End Property
Public WriteOnly Property RealStock() As Integer
Set(ByVal value As Integer)
_RealStock = value
End Set
End Property
Public Property Quantity() As Integer
Get
' Dim Qty As TextBox = Me.FindControl("txtQty")
' Me.EnsureChildControls()
Return _Quantity
'
End Get
Set(ByVal value As Integer)
' Dim Qty As TextBox = Me.FindControl("txtQty")
' Me.EnsureChildControls()
_Quantity = value
End Set
End Property
Public Overrides ReadOnly Property Controls() As ControlCollection
Get
EnsureChildControls()
Return MyBase.Controls
End Get
End Property
Protected Sub OnClick(ByVal e As EventArgs)
RaiseEvent Click(Me, e)
End Sub
Protected Overrides Sub CreateChildControls()
If _RealStock > 0 Then
Dim txtProdID As New TextBox
txtProdID.Text = Me.ProdID
Me.Controls.Add(txtProdID)
'Antal-textbox
Dim txtQty As New TextBox
txtQty.MaxLength = 3
txtQty.Columns = 3
txtQty.ID = "Qty"
txtQty.Text = Me.Quantity
Me.Controls.Add(txtQty)
Dim BuyBtn As New Button
BuyBtn.Text = "Buy"
AddHandler BuyBtn.Click, AddressOf BuyBtn_Click
Me.Controls.Add(BuyBtn)
'******** Validering ***************
Dim rv1 As New RangeValidator
rv1.ControlToValidate = txtQty.ID
rv1.MinimumValue = 0
rv1.MaximumValue = _RealStock
rv1.ErrorMessage = "*"
rv1.EnableClientScript = True
Me.Controls.Add(rv1)
Else
Dim lbOutOfStock As New Label
lbOutOfStock.Text = "Out Of Stock"
Me.Controls.Add(lbOutOfStock)
End If
End Sub
Private Sub BuyBtn_Click(ByVal Sender As Object, ByVal e As EventArgs)
OnClick(EventArgs.Empty)
End Sub
End Class
det enda som händer nu är att jag får en postback, men inget händer, ja förutom att ingen data binds till diverse kontroller i repeaterna itemtemplate