Hi,
I'm creating a shopping basket where for each item a drop down list is created and an event handler is assigned.
Suddenly my application has started ignoring my Handler. I have tried assigning to a different handler which just outputs a response.write message for debugging and this works. As soon as I switch it back to the original handler QtyChanged everything is being ignored, even the Response.Write at the start of the Sub.
If there's something blindingly obvious Ive missed or anything else please can you let me know?
cheers,
NK
my code is below:
Creating each drop down in a loop:
QtyChanged:
I'm creating a shopping basket where for each item a drop down list is created and an event handler is assigned.
Suddenly my application has started ignoring my Handler. I have tried assigning to a different handler which just outputs a response.write message for debugging and this works. As soon as I switch it back to the original handler QtyChanged everything is being ignored, even the Response.Write at the start of the Sub.
If there's something blindingly obvious Ive missed or anything else please can you let me know?
cheers,
NK
my code is below:
Creating each drop down in a loop:
VB.NET:
...
'*** Item Qty
ItemQty = Dt.Rows(i).Item("qty")
'*** Create Qty Dropdown
Dim DDQty As New DropDownList
Response.Write("before Handler add ")
AddHandler DDQty.SelectedIndexChanged, AddressOf QtyChanged
Response.Write("after handler add ")
DDQty.ID = "Qty" & i & "*" & Dt.Rows(i).Item("SkuId")
DDQty.AutoPostBack = True
Response.Write("AutoPostBack added ")
For x = StartNo To EndNo
DDQty.Items.Add(New ListItem(x, x))
Response.Write(" - " & x & "list item <br />")
Next
DDQty.SelectedValue = ItemQty
TBBasketDetail.Rows(RowNo).Cells.AddAt(Idx, New TableCell)
TBBasketDetail.Rows(RowNo).Cells(Idx).CssClass = "basketlargetd"
TBBasketDetail.Rows(RowNo).Cells(Idx).Controls.Add(DDQty)
...
QtyChanged:
VB.NET:
Sub QtyChanged(ByVal Sender As Object, ByVal e As System.EventArgs)
'Response.Write("QtyChanged entered!! <br />")
'*** Create instance of Qty Drop Down
Dim QtyDDL As DropDownList = CType(Sender, DropDownList)
Dim IDStartPos As Integer = (InStr(QtyDDL.ID, "*") + 1)
'*** Extract SkuId from Drop Down ID
Dim SkuId As Integer = CInt(Mid(QtyDDL.ID, IDStartPos, Len(QtyDDL.ID)))
Dim NewQty As Integer
Dim Loops As Integer
NewQty = QtyDDL.SelectedValue
Response.Write("NewQty = " & NewQty & "<br />")
'*** Check if we are adding or removing item
For i = 0 To Dt.Rows.Count - 1
'Response.Write("ItemQty" & Dt.Rows(i).Item("Qty") & "<br>")
If Dt.Rows(i).Item("SkuId") = SkuId Then
If NewQty > Dt.Rows(i).Item("Qty") Then
Response.Write("DT NewQty = " & Dt.Rows(i).Item("Qty") & "<br />")
TmpStr = "1"
'*** ADD AN ITEM
Loops = 0
Loops = NewQty - Dt.Rows(i).Item("Qty")
'Response.Write("Adding : " & Loops)
For x = 1 To Loops
Response.Write("x=1 loop entered for add <br />")
AddWOrderItem(Dt.Rows(i).Item("WItemId"), Dt.Rows(i).Item("WCatalogueId"), SkuId,
Dt.Rows(i).Item("PsPid"), Dt.Rows(i).Item("WCustomerCardId"), Dt.Rows(i).Item("CurrencyId"))
Next
Else
'*** REMOVE AN ITEM
TmpStr = "2"
Loops = 0
Loops = Dt.Rows(i).Item("Qty") - NewQty
'Response.Write("Removing : " & Loops)
For x = 1 To Loops
Response.Write("x=1 loop entered for subtract <br />")
RemoveWOrderItem(SkuId)
Next
End If
End If
Next
'*** Redirect back to self - Forcing new data and outside control visibility
'*** SET VARIABLES
Dim RDUrl As String
Dim CurrentUrl As String = Request.ServerVariables("SCRIPT_NAME")
Dim CurrentVars As String = Request.ServerVariables("QUERY_STRING")
RDUrl = CurrentUrl & CurrentVars
Response.Redirect(RDUrl)
End Sub