473,797 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByV al NavType As Integer) As Table
Dim NavTable As New Table
NavTable.CellSp acing = 1
NavTable.CssCla ss = "contenttab le"
NavTable.Width = Unit.Percentage (100)

Dim DataTable As AppDataSet.Navi gationDataTable =
BLL.GetNavigati onByType(NavTyp e)
Dim RSRow As AppDataSet.Navi gationRow

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(RSR ow.NavId)
Header.Text = RSRow.NavId
LinkText.Text = RSRow.LinkText
LinkUrl.Text = RSRow.LinkUrl
Sorting.Text = RSRow.Sorting
EditCell.Contro ls.AddAt(0, EditLink)
Row.Cells.Add(H eader)
Row.Cells.Add(L inkText)
Row.Cells.Add(L inkUrl)
Row.Cells.Add(S orting)
Row.Cells.Add(E ditCell)
NavTable.Rows.A dd(Row)
Next
Return NavTable
End Function

Function GetEditLink(ByV al 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 2544
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(ByV al NavID As Integer) As
LinkButton
Dim EditUrl As New LinkButton
EditUrl.Command Name = "EditComman d"
EditUrl.Command Argument = NavID.ToString( )
AddHandler EditUrl.Command , AddressOf EditNav
EditUrl.Text = "Edit"
Return EditUrl
End Function

Sub EditNav(ByVal sender As Object, ByVal e As CommandEventArg s)
If e.CommandName.C ompareTo("EditC ommand") = "0" Then
Label1.Text = "Arg: " & e.CommandArgume nt.ToString()
End If
End Sub
"Jack" <no@sp.amwrot e in message
news:uO******** ******@TK2MSFTN GP03.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(ByV al NavType As Integer) As Table
Dim NavTable As New Table
NavTable.CellSp acing = 1
NavTable.CssCla ss = "contenttab le"
NavTable.Width = Unit.Percentage (100)

Dim DataTable As AppDataSet.Navi gationDataTable =
BLL.GetNavigati onByType(NavTyp e)
Dim RSRow As AppDataSet.Navi gationRow

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(RSR ow.NavId)
Header.Text = RSRow.NavId
LinkText.Text = RSRow.LinkText
LinkUrl.Text = RSRow.LinkUrl
Sorting.Text = RSRow.Sorting
EditCell.Contro ls.AddAt(0, EditLink)
Row.Cells.Add(H eader)
Row.Cells.Add(L inkText)
Row.Cells.Add(L inkUrl)
Row.Cells.Add(S orting)
Row.Cells.Add(E ditCell)
NavTable.Rows.A dd(Row)
Next
Return NavTable
End Function

Function GetEditLink(ByV al 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
23197
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 code does not execute, it just reloads the page. Where am i going so wrong? i don't understand what's missing. many thanks in advance.
5
1640
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 WYSIWYG editor, so I co to the CodeBehind and add the Event in the InitializeComponent() Method like this this.lbTest.Click += new System.EventHandler(this.lbTest_Click); so far, all works fine. now if i go to the WYSIWYG editor, add another...
1
2495
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
2325
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 : Dim linkButton As New LinkButton linkButton.Text = name linkButton.CommandName = "PassSelectedClient" linkButton.CommandArgument = id I add it to the controls
0
2958
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 such as when they do a delete. Everything is great. By and large it will be used in my repeater controls using the command event when the user clicks on it and so that event is working great. My issue is the Click event. When the control is...
0
1906
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 table gets successfully displayed on the browser with the LinkButton. When I click on the link button in the browser, my control does not go inside the custom even that I wrote for the link button. I have a table control as ProviderTbl in which...
6
2263
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 I need to do some extra stuff in the click event of the created linkbutton. I tried to assign a delegate to the linkbutton's click event but I never gets in the procedure I assign. How can I trap the click event?
6
16882
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 quote has been submitted and an email will arrive to them shortly. I added a "Home" link button on this page which will return them to the website's home page. I want to clear out 10 session variables (contact name, ship to address, city, state,...
7
6199
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 something. The buttons show up and post back, but the events do not fire. any help would be appreciated!!! Thank you. protected void gvEntitiesRowDataBound(object sender, GridViewRowEventArgs e) {
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9536
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10205
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9063
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.