Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Adding click event to linkbutton

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jack - 28 Dec 2007 11:16 GMT
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.
Jack - 28 Dec 2007 14:42 GMT
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

> Hi,
>
[quoted text clipped - 55 lines]
>
> Tnx.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.