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

Handling events on a dynamically generated CheckBox

P: n/a
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.
May 16 '06 #1
Share this Question
Share on Google+
4 Replies


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

--
Jeffrey Hornby
Hornby Consulting, Inc.

"UJ" wrote:
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.

May 16 '06 #2

P: n/a
UJ
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.
"Jeffrey Hornby" <Je***********@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.com...
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).

--
Jeffrey Hornby
Hornby Consulting, Inc.

"UJ" wrote:
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.

May 16 '06 #3

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

May 16 '06 #4

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

"Galcho[MCSD.NET]" <ga****@gmail.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
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

May 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.