473,396 Members | 1,775 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,396 software developers and data experts.

Adding click event to linkbutton

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
1 2495
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: CodeRazor | last post by:
Hi, I am trying to dynamically create linkbuttons. They need an event handler, so i can respond to the user's click. I try to add the eventhandler on the fly, but when i click on the link, the...
5
by: Patrick | last post by:
Hello I have the following problem. I have an aspx Page. This page contains an ASP-Table Object. So in that table, I have a linkbutton. So, I can't edit the event of that button trough the...
1
by: Sheryl Landon | last post by:
Is there a way to set the OnCommand or OnClick attributes when adding a LinkButton dynamically through code? These attributes are available when adding on design-time... Thanks, Sheryl
1
by: geronimi | last post by:
I want to create a linkbutton in a cell because not every row needs one (so I can't setup a linkbuttoncolumn instead of a boundcolumn.) First, i create a linkbutton in the datagrid_ItemDataBound...
0
by: Demetri | last post by:
I have created a web control that can be rendered as either a linkbutton or a button. It is a ConfirmButton control that allows a developer to force a user to confirm if they intended to click it...
0
by: OceanBreeze | last post by:
I have added a LinkButton to a table cell programmatically inside the Page_Load method. I also added a custom event to that link button. The same custom event is valid for all the link buttons. The...
6
by: Class | last post by:
Hi all, I create a gridview dynamicly because I don't know the columns in advance. I use the Templatefield to create a linkbutton. Everything fine..I have the postbackurl and it works. But now...
6
by: Mel | last post by:
I have a website that allows the user to generate a new quote. When they are finished creating the quote, it brings them to the final page (called the Goodbye.aspx page) which just states the...
7
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I'm adding subheadings to a gridview. Each sub head has a few link buttons. I'm adding the controls in the rowdatabound event code follows: sorry about the length here. I have to be missing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.