By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,724 Members | 1,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,724 IT Pros & Developers. It's quick & easy.

Event handling for dynamically generated controls

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.