Hi Kevin,
Then why does this work?
Private Sub PopulateCategoryTable()
'Retrieve Category values from database
Dim CForm As New ClaimForm
'populate datatable
dtCategories = CForm.LoadCategories(hdnLineOfBusniessID.Value.ToU pper)
'Add 'View All Categories' option
Dim r As DataRow
r = dtCategories.NewRow()
r("CATEGORY_CODE") = "VA"
r("DESCRIPTION") = "View All Categories"
dtCategories.Rows.Add(r)
r = Nothing
For Each r In dtCategories.Rows
Dim tr As New TableRow
Dim tc As New TableCell
Dim lb As New LinkButton
lb.Text = CType(r.Item(1), String).ToUpper
lb.ID = CType(r.Item(0), String).ToUpper
AddHandler lb.Click, AddressOf ConnectCategoryLinks
tc.CssClass = "tabledata"
tc.Controls.Add(lb)
tr.Cells.Add(tc)
tblCategory.Rows.Add(tr)
lb = Nothing
tc = Nothing
tr = Nothing
Next
CForm = Nothing
End Sub
Where
Private Sub ConnectCategoryLinks(ByVal sender As System.Object, ByVal e
As System.EventArgs)
Dim tr As TableRow
Dim lb As LinkButton = CType(sender, LinkButton)
hdnSelectedCategory.Value = lb.ID
'Disable the selected category link button
For Each tr In tblCategory.Rows
CType(tr.Cells(0).Controls(0), LinkButton).Enabled = _
Not (String.Equals(CType(tr.Cells(0).Controls(0),
LinkButton).ID, lb.ID))
Next
lb = Nothing
'populate datagrid
PopulateClaimFormsDataGrid(hdnSortField.Value, hdnSortOrder.Value)
End Sub
I'm doing the exact same thing - declaring the button and adding the
handler. I don't see any difference, other than the code above declares and
adds the button to a table row and the code that I sent yesterday retrieves a
reference to the button in a datagrid. So what differnce does it make?
Thanks,
Joe
"Kevin Spencer" wrote:
Hi Joe,
When I click on one of the link buttons after it has been rendered, this
event handler never fires. Is there some obvious reason why? Can any of
you
see womething glaringly wrong with what I've written?
Yes. You've declared the button inside a function. It lives for the lifetime
of the function, and then disappears into the void. In addition, as a Page
class has a lifetime of precisely ONE Request, you will need to add the
buttons back in to the Page with each PostBack, and scope them to the Page.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
"Joe" <jo******@donotspam.yahoo.com> wrote in message
news:BF**********************************@microsof t.com...I have a datgrid with a button column that contains link buttons. I have
added code to the ItemDataBound event of the datagrid that adds a handler
to
each link button. Here is the code:
Private Sub dgForms_ItemDataBound(ByVal sender As System.Object, ByVal e
As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgForms.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim lb As LinkButton = CType(e.Item.Cells(1).Controls(0), LinkButton)
AddHandler lb.Click, AddressOf RetrieveformIdClickHandler
lb = Nothing
End If
End Sub
The RetrieveformIdClickHandler Sub follows:
Private Sub RetrieveformIdClickHandler(ByVal sender As System.Object,
ByVal
e As System.EventArgs)
Dim lb As LinkButton = CType(sender, LinkButton)
m_FormId = lb.Text
lb = Nothing
End Sub
When I click on one of the link buttons after it has been rendered, this
event handler never fires. Is there some obvious reason why? Can any of
you
see womething glaringly wrong with what I've written?
FYI, page-level ViewState is disabled on each page at this client site.
They don't allow its use.
TIA,
--
Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation