473,396 Members | 1,933 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.

Event handling for dynamically generated controls

Hi,

I am dynamically generating check boxes in the Panel control based on a
database field, and I've set the AutoPostBack property to True. How can I
determine which CheckBox caused the post back ?

Thank you,

Steve
Nov 18 '05 #1
2 1547
Steve
Have you wired a handler to the onchange change event of your dynamically generated check box

You should have something like the following prior to adding(or atleast before the response is returned) the checkbox to your panel(In C#)

CheckBox chk = new CheckBox(); //you should already have thi
chk.CheckedChanged += new System.EventHandler(this.chkRuntime_CheckedChanged ); //Event handler assignmen
myPanel.Controls.Add(chk); //you should already have thi

Then the handler method

private void chkRuntime_CheckedChanged(object sender, System.EventArgs e

Response.Write("Runtime check clicked")
HTH
Suresh

----- Steve Caliendo wrote: ----

Hi

I am dynamically generating check boxes in the Panel control based on
database field, and I've set the AutoPostBack property to True. How can
determine which CheckBox caused the post back

Thank you

Stev

Nov 18 '05 #2
You can do this as follows:
1. For each checkbox set a unique ID (in the ID property of your checkbox
object).
2. Add the same event handler to all the checkbox as follows:
AddHandler newcheck.CheckedChanged, AddressOf check_checked
where newcheck is the name of a checkbox and check_checked is the name of
the method you want the postback event to be posted to.
Apply Steps 1 and 2 for all the checkboxes created.

3. In the check_checked method (the method that handles the event of
checkbox cliecked), read the ID to know which check box was clicked
A small sample for the check_checked method is:
Private Sub check1_checked(ByVal sender As Object, ByVal e As EventArgs)
Response.Write(CType(sender, System.Web.UI.WebControls.CheckBox).ID)
End Sub

Regards
Mohamed El Ashmawy
MEA Developer Support Center
ITWorx on behalf of Microsoft EMEA GTSC

"Steve Caliendo" <sc*******@epion.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

I am dynamically generating check boxes in the Panel control based on a
database field, and I've set the AutoPostBack property to True. How can I
determine which CheckBox caused the post back ?

Thank you,

Steve

Nov 18 '05 #3

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

Similar topics

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...
6
by: Steve Caliendo | last post by:
Hi, I'm creating 5 ImageButton controls in the panel control, and I have a unique ID specified for each one. When I click on any one of them, the Page_Load executes (Of course), but how do I...
4
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
4
by: hb | last post by:
Hi, When I add an asp:button (ex: id=btnLog) on home.aspx, I need to create btnLog_Click() event in home.aspx.cs, and also link this event and the button in OnInit() method by adding:...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
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...
9
by: Sridhar | last post by:
Hi, I have created a web page which includes a place holder. I also have a dropdown list in that webpage. when I select one of the choices in that dropdown list, It will load a user control...
7
by: rsaffy | last post by:
I am having trouble with my dynamically created button's event handling. I read that the buttons need to be recreated on every trip to the server, but how exactly do you do that when the datagrid...
9
by: lilOlMe | last post by:
Hi there! I have generated a GridView that looks something like: SportName| CompanyNameX |CompanyNameY |CompanyNameZ Hockey.....| Shipping------------ |Accounting-------- |Shipping------------...
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:
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.