473,508 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I create a Linkbutton and Event Hander on the fly ?

Hi,

I am wanting to create Linkbuttons and Event Handlers on the fly.

Ideally I would be able to pass the CommandName and CommandArgument to the
Event Handler which in turn would pass these to a generic method for
processing.

I have been able to create the LinkButtons themselves on the fly. However I
haven't managed to connect the to an Event Handler.

Regards

James.

Nov 17 '05 #1
6 1928
Good question
I would love to know the answer to this too.

The thing is that I am not sure if dynamically created controls can be
referenced properly in the code behind page. What i mean is if you
dynamically created something like System.Web.UI.WebControls.TextBox
text01; , I don't think you'll be able to get the compiler to compile when
you try to reference text01 in your static code, similarly eventhandlers are
attached to any particular static control on your page. So i am not sure
what you are trying to do is possible. although it would make more sense
that it should be possible.

Call in the experts....

Cheers

J


"James Norton-Jones" <ja****************@stopford.com> wrote in message
news:3f***********************@news.easynet.co.uk. ..
Hi,

I am wanting to create Linkbuttons and Event Handlers on the fly.

Ideally I would be able to pass the CommandName and CommandArgument to the
Event Handler which in turn would pass these to a generic method for
processing.

I have been able to create the LinkButtons themselves on the fly. However I haven't managed to connect the to an Event Handler.

Regards

James.


Nov 17 '05 #2
Good question
I would love to know the answer to this too.

The thing is that I am not sure if dynamically created controls can be
referenced properly in the code behind page. What i mean is if you
dynamically created something like System.Web.UI.WebControls.TextBox
text01; , I don't think you'll be able to get the compiler to compile when
you try to reference text01 in your static code, similarly eventhandlers are
attached to any particular static control on your page. So i am not sure
what you are trying to do is possible. although it would make more sense
that it should be possible.

Call in the experts....

Cheers

J


"James Norton-Jones" <ja****************@stopford.com> wrote in message
news:3f***********************@news.easynet.co.uk. ..
Hi,

I am wanting to create Linkbuttons and Event Handlers on the fly.

Ideally I would be able to pass the CommandName and CommandArgument to the
Event Handler which in turn would pass these to a generic method for
processing.

I have been able to create the LinkButtons themselves on the fly. However I haven't managed to connect the to an Event Handler.

Regards

James.


Nov 17 '05 #3
Have a look at my previous posting 'Programatically creating Linkbuttons but
....'
Which dynamically create the controls but does not handle any events.
"James Zhuo" <na**************@optusnet.com.au> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Good question
I would love to know the answer to this too.

The thing is that I am not sure if dynamically created controls can be
referenced properly in the code behind page. What i mean is if you
dynamically created something like System.Web.UI.WebControls.TextBox
text01; , I don't think you'll be able to get the compiler to compile when
you try to reference text01 in your static code, similarly eventhandlers are attached to any particular static control on your page. So i am not sure
what you are trying to do is possible. although it would make more sense
that it should be possible.

Call in the experts....

Cheers

J


"James Norton-Jones" <ja****************@stopford.com> wrote in message
news:3f***********************@news.easynet.co.uk. ..
Hi,

I am wanting to create Linkbuttons and Event Handlers on the fly.

Ideally I would be able to pass the CommandName and CommandArgument to the Event Handler which in turn would pass these to a generic method for
processing.

I have been able to create the LinkButtons themselves on the fly.
However I
haven't managed to connect the to an Event Handler.

Regards

James.



Nov 17 '05 #4
Have a look at my previous posting 'Programatically creating Linkbuttons but
....'
Which dynamically create the controls but does not handle any events.
"James Zhuo" <na**************@optusnet.com.au> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Good question
I would love to know the answer to this too.

The thing is that I am not sure if dynamically created controls can be
referenced properly in the code behind page. What i mean is if you
dynamically created something like System.Web.UI.WebControls.TextBox
text01; , I don't think you'll be able to get the compiler to compile when
you try to reference text01 in your static code, similarly eventhandlers are attached to any particular static control on your page. So i am not sure
what you are trying to do is possible. although it would make more sense
that it should be possible.

Call in the experts....

Cheers

J


"James Norton-Jones" <ja****************@stopford.com> wrote in message
news:3f***********************@news.easynet.co.uk. ..
Hi,

I am wanting to create Linkbuttons and Event Handlers on the fly.

Ideally I would be able to pass the CommandName and CommandArgument to the Event Handler which in turn would pass these to a generic method for
processing.

I have been able to create the LinkButtons themselves on the fly.
However I
haven't managed to connect the to an Event Handler.

Regards

James.



Nov 17 '05 #5
As it turns out this is quite easy ie:

lbButton = New LinkButton

lbButton.Text = "Edit"

lbButton.CommandName = lbButton.Text

lbButton.CommandArgument = rs.Fields("Id").Value

AddHandler lbButton.Command, AddressOf Me.LinkButton_Command

"James Norton-Jones" <ja****************@stopford.com> wrote in message
news:3f***********************@news.easynet.co.uk. ..
Hi,

I am wanting to create Linkbuttons and Event Handlers on the fly.

Ideally I would be able to pass the CommandName and CommandArgument to the
Event Handler which in turn would pass these to a generic method for
processing.

I have been able to create the LinkButtons themselves on the fly. However I haven't managed to connect the to an Event Handler.

Regards

James.


Nov 17 '05 #6
Thanx for posting back James
This should come in handy later on.

Cheers

James

"James Norton-Jones" <ja****************@stopford.com> wrote in message
news:3f***********************@news.easynet.co.uk. ..
As it turns out this is quite easy ie:

lbButton = New LinkButton

lbButton.Text = "Edit"

lbButton.CommandName = lbButton.Text

lbButton.CommandArgument = rs.Fields("Id").Value

AddHandler lbButton.Command, AddressOf Me.LinkButton_Command

"James Norton-Jones" <ja****************@stopford.com> wrote in message
news:3f***********************@news.easynet.co.uk. ..
Hi,

I am wanting to create Linkbuttons and Event Handlers on the fly.

Ideally I would be able to pass the CommandName and CommandArgument to the Event Handler which in turn would pass these to a generic method for
processing.

I have been able to create the LinkButtons themselves on the fly.
However I
haven't managed to connect the to an Event Handler.

Regards

James.



Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10773
by: Kiyomi | last post by:
Hello, I create a Table1 dynamically at run time, and at the same time, I would like to create LinkButton controls, also dynamically, and insert them into each line in my Table1. I would...
3
1790
by: leon | last post by:
hello friends, i am writing a page aspx and creating controls dinamicaly and then i must to create for each control the events as well. Anybody to know how????? happy day lion
3
23179
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...
1
11537
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
10
2820
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
1
2149
by: smash2004 | last post by:
I have VS 2005 CTP. I created a page with one repeater. Inside i put a linkbutton. Usually when i put linkbutton on a page I doubleclick it in designview and event gets created in codebehind...
2
10767
by: msnews.microsoft.com | last post by:
I want to read information out of a database at runtime (names of files available to download) and create a list of linkbuttons that the user can click on to download the file(s). How can I...
1
2301
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...
1
1668
by: kaczmar2 | last post by:
I have an ASP.NET page where controls are created dynamically, and I have an issue where one event handler creates another set of controls, and then adds event handlers to those controls. The...
0
7391
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...
1
7054
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
7501
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...
0
5633
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,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3204
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...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
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 ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.