473,398 Members | 2,393 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,398 software developers and data experts.

Handling events on a dynamically generated CheckBox

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
4 1833
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: kdbarrett | last post by:
I have code that dynamically creates checkboxes at runtime. How can I capture events from those checkboxes? Thanks
2
by: Eric Newton | last post by:
VB's more declarative nature of handling events is golden. I'm hoping C# will acquire this type of deal, in addition to the anonymous delegates. could do same as vb (actually would be easier to...
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...
2
by: Steve Caliendo | last post by:
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...
4
by: JezB | last post by:
I am dynamically creating WebControls and creating them on my page. Some of these are buttons, and I attach events to these buttons. The problem is these force a post-back, so I must regenerate 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...
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
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
7
by: Srikanth Ram | last post by:
Hi, I'm creating a PHP application. In this a dynamic table with the fields in the database is generated in a page. I have placed a checkbox in each row of the table to approve/disapprove...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.