473,837 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding event handler for dynamically created controls

Hello
Please excuse me if this come in as a duplicate.

Here is the situation that I am having: I am pulling data from a database and writing it out as a list. Next to each item that I write, I want to make a linkbutton control which will allow you to invalidate the database record. Since I don't know how many records will be present, I need to have all of the linkbuttons access the same event. The trick is to know WHICH linkbutton was pressed. Is there a way that anyone can suggest to accomplish this? I have been trying to do this for a good deal of time so far
Thank you
Andre

Nov 18 '05 #1
3 1913
Andrew, I presume you are writing it out as a datalist. No matter which button the user clicks in the datalist, the ItemCommand event fires. Inside ItemCommand, e.item is the datalistitem of the row that was clicked, and in e.item.controls you'll find the data that's shown in the grid. In addition to or instead of, you can bind the linkbutton's CommandArgument property to your primary key field, then retrieve CommandArgument in ItemCommand and use it to go get your data from somewhere, etc. (this is handy when you want a key or something that you're not showing in the grid, although you can do that too with hidden fields). ht

Bil

----- Andrew Wied wrote: ----

Hello
Please excuse me if this come in as a duplicate.

Here is the situation that I am having: I am pulling data from a database and writing it out as a list. Next to each item that I write, I want to make a linkbutton control which will allow you to invalidate the database record. Since I don't know how many records will be present, I need to have all of the linkbuttons access the same event. The trick is to know WHICH linkbutton was pressed. Is there a way that anyone can suggest to accomplish this? I have been trying to do this for a good deal of time so far
Thank you
Andre

Nov 18 '05 #2
Thank you for the reply
Actually, I'm not using a datalist. Basically, I am wondering if there is a way to get two or more (a variable quantity) of controls[linkbuttons, specifically] to fire the same event, and have the event handler know which one threw the event

Is there a way that anyone knows

Thanks
Andre

----- Bill Borg wrote: ----

Andrew, I presume you are writing it out as a datalist. No matter which button the user clicks in the datalist, the ItemCommand event fires. Inside ItemCommand, e.item is the datalistitem of the row that was clicked, and in e.item.controls you'll find the data that's shown in the grid. In addition to or instead of, you can bind the linkbutton's CommandArgument property to your primary key field, then retrieve CommandArgument in ItemCommand and use it to go get your data from somewhere, etc. (this is handy when you want a key or something that you're not showing in the grid, although you can do that too with hidden fields). ht

Bil

Nov 18 '05 #3
Just attach the same handler to the event you want from each of the controls, then in the handler use the "sender" object to figure out who sent it--e.g. you've got a bunch of buttons, you attach MyButtonHandler to each button's Click event, and then in MyButtonHandler you do something like (button)sender. name to figure out who was clicked. Does that help

----- Andrew Wied wrote: ----

Thank you for the reply
Actually, I'm not using a datalist. Basically, I am wondering if there is a way to get two or more (a variable quantity) of controls[linkbuttons, specifically] to fire the same event, and have the event handler know which one threw the event

Is there a way that anyone knows

Thanks
Andre

----- Bill Borg wrote: ----

Andrew, I presume you are writing it out as a datalist. No matter which button the user clicks in the datalist, the ItemCommand event fires. Inside ItemCommand, e.item is the datalistitem of the row that was clicked, and in e.item.controls you'll find the data that's shown in the grid. In addition to or instead of, you can bind the linkbutton's CommandArgument property to your primary key field, then retrieve CommandArgument in ItemCommand and use it to go get your data from somewhere, etc. (this is handy when you want a key or something that you're not showing in the grid, although you can do that too with hidden fields). ht

Bil

Nov 18 '05 #4

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

Similar topics

3
23201
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.
3
4891
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
1
1676
by: Greg | last post by:
In my ASP.NET application I have a button that when pressed, data needs to be saved based on what the user typed in. I have other controls on the same page that should be updated as a result of the save, which are all dynamically created in the code behind and have event handlers registered. In the page life cycle, event handlers are called after the page is loaded. The problem is, the save is done after the controls are loaded, so the...
2
2113
by: Tim Marsden | last post by:
Hi, This is what I am doing, please comment if this is the correct way. I need to add controls to a form dynamically. Within the Page_Load event (is not Postback) I run a routine to create the controls, and populate the dropdowns etc, I use addhandler to define delegates to capture events raised by the controls. I store these controls in a hashtable.
4
2504
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in the table. I know that I can dynamically add controls (eg a textbox) to the page controls collection of a web form in a server event which will then be rendered onto the form, as in the following snippet: System.Web.UI.WebControls.TextBox...
2
3051
by: Shiju Poyilil | last post by:
Hi ! I have a requirement wherein i am binding a datalist which contains a label (Caption for the field) and some literal hidden fields and a dropdown list. When I am binding to the datalist.. only the labels (caption) and the invisible literal controls are binded.. Now based on the invisible literal control values I get the information from DB to bind it with each dropdown list (I am doing this in the item databound event) Also based on...
3
2349
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example ABAP, BDC etc..etc.. on every click event as Checkboxes. And these controls(checkboxes) should remain...
9
14471
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The problem is that the webcontrols get created on the OnLoad event of the usercontrol and the event handlers are assigned at the same time. I have to click twice on the controls for the events to be raised, the first time nothing...
9
2795
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT IS IMPOSSIBLE TO PROGRAMMATICALLY ADD A BUTTON TO A DYNAMICALLY CREATED PAGE. Or, to be more precise, why it is impossible to have an onClick sub respond to that button’s Click event. My main page has only one line:
0
9853
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
10584
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10644
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
10289
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
9423
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
7014
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
5681
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...
2
4062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3131
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.