0

I've been reading posts and articles and just getting a little confused and consequently burning through time I don't have at the moment

Can someone look at my code and tell me where I've gone wrong?

    Partial Class PayerContacts
    Inherits System.Web.UI.Page

    Dim connStrDRContacts As String = ConfigurationManager.ConnectionStrings("DRContacts_SQL").ConnectionString

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        navBuild()
    End Sub

    Protected Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init

        If IsPostBack Then
            LoadContacts(ViewState("objSender"))
        End If

    End Sub

    Private Function navBuild() As Integer

        Dim SQLstrDRs As String = "SELECT * FROM DRList"
        Dim DbConnDRs As SqlConnection = New SqlConnection(connStrDRContacts)
        DbConnDRs.Open()
        Dim dtDRsTemp As New DataTable
        Dim SQLAdapterDRs As New SqlDataAdapter(SQLstrDRs, DbConnDRs)
        SQLAdapterDRs.Fill(dtDRsTemp)

        'Loop through each row of the DataView to create HTML table data

        Dim NewTableRow As New TableRow

        For Each row As DataRow In dtDRsTemp.Rows

    'CREATE table with button to display contacts related to client (one to many)   
            Dim NewTableButton As LinkButton = New LinkButton
            NewTableButton.ID = "btnDRName" & NewTableText
            NewTableButton.ViewStateMode = UI.ViewStateMode.Enabled
            AddHandler NewTableButton.Click, AddressOf LoadContacts

        Next

        Return 0

    End Function

    Protected Sub LoadContacts(sender As Object, e As EventArgs)

        Dim LoopCount As Integer = 0

        Dim SQLstrLoadTable As String = "SELECT * FROM ContactList WHERE DRVendor = '" & sender.Text.ToString & "'"
    and so on....
        SQLAdapterLoadTable.Fill(dtLoadTableTemp)

        Dim NewTableRow As New TableRow

        For Each row As DataRow In dtLoadTableTemp.Rows

            'CREATE Accordion to display data
            NewAccordion.ID = "ContactAccordion" & LoopCount
            NewAccordion.Visible = True
    blah, blah...

            'SET Pane
            NewAccordionPane.HeaderContainer.ID = "PaneHeader" & LoopCount
            NewAccordionPane.ContentContainer.ID = "PaneContent" & LoopCount

    'CREATE button to open ModalPopup to EDIT each record
            Dim imgGear As New ImageButton
            imgGear.ID = "btnGear" & row!ID.ToString
            imgGear.ViewStateMode = UI.ViewStateMode.Enabled
            AddHandler imgGear.Click, AddressOf EditRecord

            'LOAD Pane
            NewAccordionPane.HeaderContainer.Controls.Add(NewHeaderTable)
            NewAccordionPane.ContentContainer.Controls.Add(New LiteralControl(NewTableText))


        ViewState("objSender") = sender

    End Sub

    Protected Sub EditRecord(ByVal sender As Object, ByVal e As EventArgs)
        'Open ModalPopup to edit record
        popup.Show()
        pnlAddEdit.Visible = True

    End Sub

End Class
Tim
  • 41,901
  • 18
  • 127
  • 145
mreinsmith
  • 154
  • 3
  • 14
  • What are you trying to do? What's broken? Have you tried debugging? Also, please reduce the code to the minimum needed to reproduce the issue. (Sometimes this process is enough to figure out the problem on its own!) – Barett Apr 29 '15 at 04:06
  • OK, I narrowed it down. WHat I'm trying to do is open a page with a NAVbar and list all the clients, you click on that clients name and it brings up collapsible "contact cards" for each contact. THen there is a gear icon in the header of each contact card (accordion ) that you click to edit that individual contact (a modal popup to edit) – mreinsmith Apr 29 '15 at 04:17
  • The client list navbar works and brings up the contacts related to the client. But I can't get the gear icon to open the Modal popup. Passing the handler from over the postback doesn't seem to be working – mreinsmith Apr 29 '15 at 04:21
  • BTW, That's a good point, narrow it down to the basic function, I'll keep looking at that. Thanks – mreinsmith Apr 29 '15 at 04:26

1 Answers1

0

The Infinities Loop articles on ViewState and Dynamic Controls should really be read by every Webforms developer: -

http://mocha.mojoskins.com/SharedFiles/Download.aspx?pageid=566&mid=786&fileid=38

http://weblogs.asp.net/infinitiesloop/TRULY-Understanding-Dynamic-Controls-_2800_Part-1_2900_

The examples are in C# but you should be able to figure out what's going on, it's the same base class library after all.

sh1rts
  • 1,874
  • 1
  • 13
  • 14
  • The Viewstate one is here - http://weblogs.asp.net/infinitiesloop/Truly-Understanding-Viewstate - but it seems to be missing images. Still readable though, and a very good (and accurate) explanation of how ViewState works and how you should use it. – sh1rts Apr 29 '15 at 05:43