Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Event not called for LinkButton 1

Status
Not open for further replies.

Peppi

Programmer
Joined
Apr 9, 2001
Messages
205
Location
CA
Hi,

I have the following code for my link button:

link.ID = "lnkRFS"
link.Text = dataReader("RfsNo")
link.CommandName = "RFSNo"
link.CommandArgument = dataReader("RfsNo")
AddHandler link.Command, AddressOf Me.lnkRFS_Command

And the event handler:

Private Sub lnkRFS_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim RFSNo As String

RFSNo = CType(e.CommandArgument, String)
lblRfsNo.Value = RFSNo
lblGridDescription.Value = "Stages"
End Sub

When I click on the link, the lnkRFS_Command event handler is not getting called and I can't figure out why?

Any help is appreciated.

Thx.
 
are you missing this:

Private Sub lnkRFS_Command(ByVal sender As Object, ByVal e As CommandEventArgs) [red]Handles lnkRFS.Click[/red]

-DNG
 
I'd thought that when you use AddHandler, you don't need to use a Handles clause because then you need a WithEvents as well? I need to dynamically add the event handler so I don't think the Handles clause will work. Unless I am misinterpreting the documentation that I have read.
 
Nuts, I think I have to recreate the link button controls on postback in order for their event handlers to run.

 
If this is a dynamic control, you need to recreated it on each post back, along with any event handlers. Use the Page_Init event to create them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top