Handling events on a dynamically generated CheckBox

  • Thread starter Thread starter UJ
  • Start date Start date
U

UJ

I've got an page that dynamically generates a table (don't ask!) that
includes in each cell a checkbox. I can get the checkbox create but I can't
figure out how to get an event tied to it so that when the person changes
the value, I get notification.

Also - there appears to be no runat property when I create the checkbox. Is
this automatically true?

TIA - Jeff.
 
Write a function with the correct signature (void fn(object sender, EventArgs
e)) and assign it to the CheckedChanged event. The syntax is like this:

checkbox1.CheckChanged += new EventHandler(this.fn);

The same function can be used for all of your checkboxes. A reference to
the checkbox will be found in the sender argument (you'll need to cast it to
use it).
 
OK. I screwed up. I posted my message in C# when I'm actually doing VB code.
(I do the majority of stuff in C# but this is in VB.)

Could somebody verify for me that this would be equivalent?

Dim lcbSelect As CheckBox = New CheckBox
lcbSelect.Text = "Selected"
Dim lbSelected As Boolean =
Convert.ToBoolean(dRow("Selected"))
lcbSelect.Checked = lbSelected
lcbSelect.AutoPostBack = True
AddHandler lcbSelect.CheckedChanged, AddressOf
SelectClicked

SelectClicked is defined as

Protected Sub SelectClicked(ByVal sender As Object, ByVal e As
EventArgs)


I'm doing the definition for the checkbox in a call from Pre_Render.

My SelectClicked never gets called.

Anybody have any help?

Again I apologize for putting this in C#.

TIA - an Embarrassed Jeff.
 
you define control right
but I do not see code for adding it to some container control.
Do you add it to Page?

I hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com
 
Actually a friend of mine solved the problem. I now create all of the
objects in OnInit which makes the viewstate there. Then the routine for
checkchanged is called correctly.

Thanks anyway.
 
Back
Top