By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,115 Members | 894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,115 IT Pros & Developers. It's quick & easy.

Adding click event to linkbutton

P: n/a
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.
Dec 28 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
"Jack" <no@sp.amwrote in message
news:uO**************@TK2MSFTNGP03.phx.gbl...
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.

Dec 28 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.