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

Handling events of controls created at runtime

Subject: Handling events of controls created at runtime

I need to render some buttons at runtime based on a database, tie events to
them, and handle the events when they fire.

In Page_Load I create the controls (for example a delete-button), add them
to a placeholder, add eventhandlers, and the controls are displayed as
expected.

I click the button, the event fires as I wanted, I delete a record in the
database, and now I want to re-render the entire thing to reflect the
changes in the database.

This is where my problems start...

If I clear the placeholder and render the buttons/controls again, the
eventhandlers work. I click a button, no event is fired.
I currently work around this by response.redirecting to the page again - and
this created an illusion of what I want, but is not the right way to handle
this.
Please note, that this is a simplified example - obviously there was no need
to generate controls at runtime, if it could be solved by using a datagrid
or something like that. :)
Jun 21 '07 #1
1 1708
Hi,

Do you assign ID to your controls when you create them? If you don't, try
assigning ID in a way that button for the same row has the same ID after
you clear placheholder an add controls back. When you clear placeholder
and add controls back, they get new IDs. However, on the next postback they
get their old IDs.

See http://www.singingeels.com/Articles/...in_ASPNET.aspx.
I think I described the problem you expirience.

-yuriy

Subject: Handling events of controls created at runtime

I need to render some buttons at runtime based on a database, tie
events to them, and handle the events when they fire.

In Page_Load I create the controls (for example a delete-button), add
them to a placeholder, add eventhandlers, and the controls are
displayed as expected.

I click the button, the event fires as I wanted, I delete a record in
the database, and now I want to re-render the entire thing to reflect
the changes in the database.

This is where my problems start...

If I clear the placeholder and render the buttons/controls again, the
eventhandlers work. I click a button, no event is fired.

I currently work around this by response.redirecting to the page again
- and this created an illusion of what I want, but is not the right
way to handle this.

Please note, that this is a simplified example - obviously there was
no need to generate controls at runtime, if it could be solved by
using a datagrid or something like that. :)

Jun 21 '07 #2

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

Similar topics

4
by: blue | last post by:
I have a drop-down list, a radio button list and a submit button. I'm adding these controls to a table and I'm adding the table to a Placeholder. I'm adding it to the Placeholder because I don't...
2
by: luca | last post by:
I'm trying to build a Server Control, it's a calendar to manage sellers appointments (don't answer me to use and custumize Calendar Control because unluckily it's not possible for this specific...
0
by: luca | last post by:
Hi all. My problem is that I can't handle events raised from child components within a composite server control when the control is created dynamically. Everything works fine if the same control...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
12
by: Jack Russell | last post by:
My unstanding of all VB up to and including vb6 is that an event could not "interrupt" itself. For instance if you had a timer event containing a msgbox then you would only get one message. ...
1
by: krishna | last post by:
Hi, Hi, I would like to handle the events for the dynamically created controls at runtime. I Have written the code in HTML View of an asp.net page.like this
7
by: Bruce HS | last post by:
I'd like to call my ancestor Validation Function every time any control on a Win Form generates a Validating or Validated event. I'm using VB. I've extended Textbox, for instance, to have its...
3
by: Jose Fernandez | last post by:
Hello. I would like to know how could i get all the subscriptions that my form has with the events of their controls. For example. I have a form with a textbox, a button and a dropdown. I...
5
by: =?Utf-8?B?TWFyYyBXb29sZnNvbg==?= | last post by:
Hi, I have a strange issue occurring with LinkButtons that are dynamically added to each (data) row of my DataGrid on that grid's ItemDataBound event. Each LinkButton is assigned its own event...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.