Adding click event to linkbutton


J

Jack

Hi,

I am new to .NET and need help with adding click event on LinkButton
programatically.

Please see the code below. I would like to add a click event on LinkButton
returned from "Function EditLink". This LinkButton should fire "Sub EditNav"
when clicked.
======================================

Function GetNavTable(ByVal NavType As Integer) As Table
Dim NavTable As New Table
NavTable.CellSpacing = 1
NavTable.CssClass = "contenttable"
NavTable.Width = Unit.Percentage(100)

Dim DataTable As AppDataSet.NavigationDataTable =
BLL.GetNavigationByType(NavType)
Dim RSRow As AppDataSet.NavigationRow

For Each RSRow In DataTable
Dim Row As New TableRow
Dim Header As New TableCell
Dim LinkText As New TableCell
Dim LinkUrl As New TableCell
Dim Sorting As New TableCell
Dim EditCell As New TableCell
Dim EditLink As New LinkButton
EditLink = GetEditLink(RSRow.NavId)
Header.Text = RSRow.NavId
LinkText.Text = RSRow.LinkText
LinkUrl.Text = RSRow.LinkUrl
Sorting.Text = RSRow.Sorting
EditCell.Controls.AddAt(0, EditLink)
Row.Cells.Add(Header)
Row.Cells.Add(LinkText)
Row.Cells.Add(LinkUrl)
Row.Cells.Add(Sorting)
Row.Cells.Add(EditCell)
NavTable.Rows.Add(Row)
Next
Return NavTable
End Function

Function GetEditLink(ByVal NavID As Integer) As LinkButton
Dim EditLink As New LinkButton
'How to make this LinkButton fire the "Sub EditNav" and pass
parameter NavID?
Return EditLink
End Function

Sub EditNav(ByVal NavIID As Integer)
'Code to execute when EditLink is clicked on.
End Sub

=======================================
Any help will be appriciated.

Tnx.
 
Ad

Advertisements

J

Jack

After searching through the net and pulling my hair for a couple of hours, i
have now figured out how to do this. :)

In case anyone is interested in knowing, here is how we add an event handler
on a dynamic button/linkbutton:

Public Shadows Function GetEditLink(ByVal NavID As Integer) As
LinkButton
Dim EditUrl As New LinkButton
EditUrl.CommandName = "EditCommand"
EditUrl.CommandArgument = NavID.ToString()
AddHandler EditUrl.Command, AddressOf EditNav
EditUrl.Text = "Edit"
Return EditUrl
End Function

Sub EditNav(ByVal sender As Object, ByVal e As CommandEventArgs)
If e.CommandName.CompareTo("EditCommand") = "0" Then
Label1.Text = "Arg: " & e.CommandArgument.ToString()
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top