Connecting Tech Pros Worldwide Help | Site Map

addhandler event not firing

Newbie
 
Join Date: Jun 2007
Posts: 7
#1: Jun 14 '07
here im trying to create imagebuttons dynamically, and on click of button, the delete function should be called.

actually commandargument is not passed into the imgBtn_Click
im not getting any errors
but its not working
plz help
its very urgent


thanx in advance

here is the code....

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Public Class mbrSetClientManufacturer
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

Protected WithEvents ddlProductType As System.Web.UI.WebControls.DropDownList
Protected WithEvents ddlManufacturer As System.Web.UI.WebControls.DropDownList
Protected WithEvents btnAdd As System.Web.UI.WebControls.Button
Protected WithEvents frmSetProductType As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents tblProductTypeNumber As System.Web.UI.WebControls.Table
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents ddlClient As System.Web.UI.WebControls.DropDownList
Protected WithEvents tblClientNumber As System.Web.UI.WebControls.Table
Protected WithEvents frmSetClient As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents imgBtn As System.Web.UI.WebControls.ImageButton
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

End Sub
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

#End Region


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

btnAdd.Attributes.Add("onclick", "return validate();")
If Not Page.IsPostBack Then

Dim dtManufacturer As New DataTable
Dim dtClient As New DataTable

Dim objClientManufacturer As New ClientProductManufacturerDetails
dtClient = objClientManufacturer.grsClientNamelist(Session("F P_companyId"))
dtManufacturer = objClientManufacturer.grsManufacturerName(Session( "FP_companyId"))

ddlClient.Items.Add(New ListItem("select from..", 0))
ddlManufacturer.Items.Add(New ListItem("select from..", 0))
Dim drClient As DataRow
For Each drClient In dtClient.Rows
ddlClient.Items.Add(New ListItem(drClient("ClientName").ToString, drClient("FP_ClientID").ToString))
Next
Dim drManufacturer As DataRow
For Each drManufacturer In dtManufacturer.Rows
ddlManufacturer.Items.Add(New ListItem(drManufacturer("SupplierName").ToString, drManufacturer("FP_ProductSupplierCompanyID").ToSt ring))
Next

Dim modesave As String
modesave = Request.QueryString.Item("mode")
If (modesave = "frmsav") Then
gentable()
ddlClient.SelectedValue = Request.QueryString.Item("FP_ClientID").ToString
ddlManufacturer.SelectedValue = Request.QueryString.Item("FP_ProductSupplierCompan yID").ToString
modesave = " "
End If

End If

End Sub


Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If (ddlClient.SelectedIndex <> 0) And (ddlManufacturer.SelectedIndex <> 0) Then
Response.Redirect("mbrSetClientManufacturerEdit.as px?FP_ClientID=" & ddlClient.SelectedItem.Value & "&FP_ProductSupplierCompanyID=" & ddlManufacturer.SelectedItem.Value)
End If
End Sub

Private Sub ddlClient_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlClient.SelectedIndexChanged
gentable()
End Sub

Private Sub ddlManufacturer_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlManufacturer.SelectedIndexChanged
gentable()
End Sub


Private Sub gentable()
Dim dtGenClient As DataTable
Dim objGenClientNumbers As New ClientProductManufacturerDetails
dtGenClient = objGenClientNumbers.GenClientNumbers(Session("FP_C ompanyID"), ddlManufacturer.SelectedItem.Value, ddlClient.SelectedItem.Value)

Dim lit As LiteralControl
Dim cell As TableCell
Dim dr As DataRow

If ((ddlClient.SelectedIndex > 0) And (ddlManufacturer.SelectedIndex > 0)) Then
For Each dr In dtGenClient.Rows
Dim row As New TableRow
tblClientNumber.Rows.Add(row)
lit = New LiteralControl(dr("ClientNumber").ToString)
cell = New TableCell
cell.Controls.Add(lit)
cell.HorizontalAlign = HorizontalAlign.Center
row.Cells.Add(cell)
If (dr("inuse") = 0) Then
buildimagebutton(row, dr("FP_ManufacturerClientNumberID"))
Else
buildimagebutton(row, Nothing)

End If

Next
If dtGenClient.Rows.Count <= 0 Then
Label1.Visible = True
Else
Label1.Visible = False

End If
End If
End Sub

Private Sub buildimagebutton(ByVal row As TableRow, ByVal cid As Integer)
Dim cell As New TableCell
Dim imgBtn As New ImageButton
AddHandler imgBtn.Command, AddressOf imgBtn_Click
If (cid <> Nothing) Then
imgBtn.ImageUrl = "../images/btn_delete.gif"
Else
imgBtn.ImageUrl = "../images/btn_spacer.gif"
End If
imgBtn.CommandArgument = cid

cell.Controls.Add(imgBtn)
cell.HorizontalAlign = HorizontalAlign.Center
cell.VerticalAlign = VerticalAlign.Middle
row.Cells.Add(cell)

End Sub


Sub imgBtn_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
Dim objdel As New ClientProductManufacturerDetails
objdel.delManufacturerClientNumber(Session("FP_Com panyID"), e.CommandArgument)

End Sub



End Class
kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
#2: Jun 14 '07

re: addhandler event not firing


Welcome to TSDN. I believe that the sequence of events is a problem. I believe you need to create the image in the onload and dynamically change it later - but the object needs to exist earlier even if visibility is false. I also foresee problems with three of your functions. HTH.
Newbie
 
Join Date: Jun 2007
Posts: 7
#3: Jun 18 '07

re: addhandler event not firing


thanx for ur reply kenobewan

i have changed my code and created the imagebutton in the onload. now it works, but the page doen't get refreshed once i click on imagbutton which on click deletes one row in the table.

can u plz tell me how to refresh a page after eventhandling.


Quote:

Originally Posted by kenobewan

Welcome to TSDN. I believe that the sequence of events is a problem. I believe you need to create the image in the onload and dynamically change it later - but the object needs to exist earlier even if visibility is false. I also foresee problems with three of your functions. HTH.

Reply