We help IT Professionals succeed at work.
Get Started

AddHandler not recognized in .net 2.0

TMPSupport
TMPSupport asked
on
492 Views
Last Modified: 2010-05-18
Hi,

Our company usually works with C#, but this is an old piece of code that was written in VB.NET. The issue we're having with this was that the AddHandler does not seem to be working when we change the framework from .net 1.1 to 2.0 on the server.

Its been a while I worked on VB itself, please help me find out the bug as to why this code works good on .net 1.1 and not on 2.0.

<code>
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        '0 = Denied, 1 = Non-Denied
        Session("ShowType") = Request.QueryString("show")

        If Not Page.IsPostBack Then
            If Request.QueryString("from") <> "" Then
                If Session("AllPostings") = 1 Then
                    chkIncludeExp.Checked = True
                End If

                LoadCurrentPostings()

                lstCurrentPostings.Items.FindByValue(PostID).Selected = True
                LoadApplicants()
            Else
                LoadCurrentPostings()
            End If
        Else
            LoadApplicants()
        End If

    End Sub

   Private Sub LoadApplicants()
        m_bus = New business
        Dim DS, DS2 As DataSet
        Dim r, emp_r As DataRow
        Dim appTable As HtmlTable
        Dim appR As HtmlTableRow
        Dim appC As HtmlTableCell
        Dim objButton As Button
        Dim i As Integer
        Dim BgColor As String


        ' Get the data from the database
        Try
            If Session("ShowType") = "1" Then
                DS = m_bus.Return_Posting_Applicants(lstCurrentPostings.SelectedItem.Value)
            Else
                DS = m_bus.Return_Posting_Applicants_Denied(lstCurrentPostings.SelectedItem.Value)
            End If

            AvailableCandidates = DS

            If DS.Tables(0).Rows.Count > 0 Then
                appTable = New HtmlTable

                appTable.CellPadding = "5"
                appTable.CellSpacing = "0"
                appTable.Width = "560"

                i = 0

                For Each r In DS.Tables(0).Rows
                    ' Create each applicants info.
                    DS2 = m_bus.Return_Limited_App_Emp_History(r("app_id"))

                    appR = New HtmlTableRow

                    If i Mod 2 = 0 Then
                        BgColor = "#eae9e7"
                    Else
                        BgColor = "#FFFFFF"
                    End If

                    appR.BgColor = BgColor
                    appR.Attributes.Add("width", "560")
                    appR.VAlign = "top"

                    appC = New HtmlTableCell

                    appC.InnerHtml = "<b>" & r("app_fname") & " " & r("app_lname") & "</b><br>"
                    appC.InnerHtml &= r("app_address1") & "<br>"
                    If Not IsDBNull(r("app_address2")) Or Trim(r("app_address2")) <> "" Then
                        appC.InnerHtml &= r("app_address2") & "<br>"
                    End If
                    appC.InnerHtml &= r("app_city") & ", " & r("app_state") & " " & r("app_zipcode") & "<br><br>"
                    appC.InnerHtml &= "Salary Req: " & r("app_expected_salary_lower")

                    If Not IsDBNull(r("app_expected_salary_upper")) Then
                        appC.InnerHtml &= " - " & r("app_expected_salary_upper")
                    End If

                    appR.Cells.Add(appC)  ' add the first cell

                    appC.Dispose()
                    appC = New HtmlTableCell

                    appC.InnerHtml = "<b>Employment History</b><br>"

                    For Each emp_r In DS2.Tables(0).Rows
                        ' create the employment history located in the DS2 Dataset.
                        appC.InnerHtml &= emp_r("eh_company_name") & ": " & Month(emp_r("eh_start_date")) & "/" & Year(emp_r("eh_start_date")) & "-"
                        If emp_r("eh_current_job") = 1 Then
                            appC.InnerHtml &= "PRESENT"
                        Else
                            appC.InnerHtml &= Month(emp_r("eh_end_date")) & "/" & Year(emp_r("eh_end_date"))
                        End If
                        appC.InnerHtml &= "<br>"
                    Next

                    appR.Cells.Add(appC) ' add the second cell

                    appTable.Rows.Add(appR) ' add the row

                    appR.Dispose()
                    appC.Dispose()

                    appR = New HtmlTableRow
                    appC = New HtmlTableCell

                    appR.BgColor = BgColor
                    appC.ColSpan = "2"
                    appC.InnerHtml = "&nbsp;"

                    appR.Cells.Add(appC)

                    appTable.Rows.Add(appR)

                    appR.Dispose()
                    appC.Dispose()

                    appR = New HtmlTableRow
                    appC = New HtmlTableCell

                    appR.Align = "right"
                    appR.BgColor = BgColor
                    appC.ColSpan = "2"

                    ' Create and Add button to Cell
                    objButton = New Button
                    objButton.Text = " View Applicant Info "
                    objButton.ID = "btnAppID_" & CStr(r("app_id")) ' apphend app ID to signify button
                    objButton.Enabled = True
                    AddHandler objButton.Click, AddressOf Me.Button_ProcessClick

                    'AddHandler objButton.Click, AddressOf Me.Button_ProcessClick
                    appC.Controls.Add(objButton)
                    objButton.Dispose()

                    objButton = New Button
                    objButton.Text = "Deny App"
                    objButton.ID = "btnDenyID_" & CStr(r("app_id")) ' apphend app ID to signify button
                    AddHandler objButton.Click, AddressOf Me.Button_ProcessDeny
                    objButton.Enabled = True
                    appC.Controls.Add(objButton)
                    objButton.Dispose()

                    appR.Cells.Add(appC)

                    appTable.Rows.Add(appR)

                    appR = New HtmlTableRow
                    appC = New HtmlTableCell

                    appR.BgColor = BgColor
                    appC.Align = "Left"
                    appC.InnerHtml = "&nbsp;"
                    appC.InnerHtml &= "Applied: " & Month(r("app_date_submitted")) & "/" & Day(r("app_date_submitted")) & "/" & Year(r("app_date_submitted"))

                    appR.Cells.Add(appC)

                    appC = New HtmlTableCell

                    appR.BgColor = BgColor
                    '   appC.ColSpan = "2"
                    appC.Align = "Right"
                    appC.InnerHtml = "&nbsp;"
                    appC.InnerHtml &= "Status: " & r("status_desc")

                    appR.Cells.Add(appC)

                    appTable.Rows.Add(appR)

                    i += 1
                Next
                pnlApplicants.Controls.Add(appTable)

                lblNoApplicants.Visible = False
            Else
                lblNoApplicants.Visible = True
            End If
        Catch e As Exception
            pnlApplicants.Controls.Clear()
            Exit Sub
        End Try
    End Sub

    Sub Button_ProcessClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim sb As StringBuilder
        Dim objEventLog As New EventLog
        Response.Write(String.Format("Write occurred at {0}", DateTime.Now.ToString()))

        Try
            Session("Controls") = "On"
            ' Parse the ID from the END of the button through splitting the string on the underscore.
            ' Pass the ID to the redirect for the applicant page.
            Dim sButton() As String = Split(CType(sender, Button).ID, "_")
            AppID = CInt(sButton(1))
            sb = New StringBuilder
            sb.AppendFormat("AppID: {0}{1}", AppID, Environment.NewLine)

            Dim foundRow As DataRow() = AvailableCandidates.Tables(0).Select("app_id = " & AppID.ToString())

            Dim i As Integer = 0
            Dim dr As DataRow
            For Each dr In AvailableCandidates.Tables(0).Rows
                If (dr("app_id") = foundRow(0)("app_id")) Then
                    SelectedCandidateRowIndex = i
                    sb.AppendFormat("Selected Candidate {0}{1}", i, Environment.NewLine)
                    Exit For
                End If
                i += 1
            Next
            sb.AppendFormat("Log entry: {0}{1}", DateTime.Now.ToString(), Environment.NewLine)
            objEventLog.WriteEntry(sb.ToString())

            Response.Redirect("applicantinfo.aspx", False)

        Catch ex As Exception
            objEventLog.WriteEntry(String.Format("{0}Message: {1} Stack: {2} Source: {3}", Environment.NewLine, ex.Message, ex.StackTrace, ex.Source))
        Finally
        End Try

    End Sub
</code>

Thanks
TMPSupport
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
This problem has been solved!
Unlock 2 Answers and 14 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE