Dynamic Control capture button click.

S

sakieboy

I have dynamically added controls using a Placeholder to a form. This form
is data driven thus I never know how many records will be retrieve. My form
looks like this
txtKey0=1111, txtBox0, txtDate0, btnEdit0
txtKey1=2323, txtBox1, txtDate1, btnEdit1
txtKey2=4343, txtBox2, txtDate2, btnEdit2
etc.

When I select a button I need to find out what my txtkey value is so that I
can pass it to a Querystring and display another page. Of course, currently
I only have one btnEdit_Click event which seems pretty lost. How do I get my
key values depending upon the button that I select. Or would I be better off
putting this in a datagrid control?
 
W

Wilco Bauwer

A datagrid, repeater or datalist may be a good choice. If you do not
use that, then you can set the button's CommandName and CommandArgument
properties. Instead of handling their click event, you should then
handle the Command event. All controls' Command event can have the same
event handler. Inside that event handler you can then extract the
information from the CommandName/CommandArgument properties to do your
thing.

In case you have problems related to dynamically loaded controls, you
may also want to take a look at
http://wilcoding.xs4all.nl/Wilco/View.aspx?NewsID=147.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top