473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

AddHandler question

Joe
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
Nov 19 '05 #1
2 1873
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

Nov 19 '05 #2
JJ
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


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: EMW | last post by:
I use the following code in the POPUP event of a contextmenu: mnuItem = New MenuItem mnuItem.Text = "Shelter" cmThs.MenuItems.Add(mnuItem) AddHandler mnuItem.Click, AddressOf MenuItemClicked...
3
by: Jeffrey A. Voigt | last post by:
Can someone take a quick glace at my code and tell me why my AutoPostBackHandler function does not get fired off at all? What I'm trying to do is get all of the Buttons and DropDownList controls...
4
by: DJ | last post by:
Good morning, Still new at this so please bear with me. I am creating a table dynamically using webcontrols based on the output of a sproc from my database.The table represents test instances...
2
by: Just Me | last post by:
When a document is to be printed I call a method that contains an AddHandler statement. I just realized that if a second copy is to be printed the method is called and the AddHandler is executed...
1
by: EMW | last post by:
I use the following code in the POPUP event of a contextmenu: mnuItem = New MenuItem mnuItem.Text = "Shelter" cmThs.MenuItems.Add(mnuItem) AddHandler mnuItem.Click, AddressOf MenuItemClicked...
3
by: hartley_aaron | last post by:
Hi, I was trying to store the address of the my current handler for a particular event so as to simplify using AddHandler and RemoveHandler throughout my code. However, I cannot seem to get any...
12
by: Tom | last post by:
I use dynamically created controls all the time. I.E. I create the control in code then use AddHandler to add the necessary delegates for processing (like Click, etc). Does one have to call...
15
by: Nathan Sokalski | last post by:
I have a section of my code that dynamically creates LinkButtons to allow the user to go to the page containing a question they have not answered. The code that creates the LinkButton is called, as...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.