How to get a control... asp (c#)

F

flyingAway

Hi,

in a for-next loop i create some ImageButtons in runtime.
How to get the controls after I clicked one of these Buttons?
I tried it with
ctrlCurrImgBtn =
(ImageButton)Convert.ChangeType(FindControl(CurrID),typeof(ImageButton));
but I get a System.NullReferenceException.
I tried to create the Controls once more but I get an Exeption because
there are more than one Control with the same ID.

Some Ideas?

Thank's
 
S

Scott Allen

All of the controls need a unique ID. Perhaps you can double check the
ID you are searching for with FindControl to the control ID you see
when you do a View Source on the page in IE.
 
F

flyingAway

I know the IDs, because I created it. (ImgBtn_1_1, ImgBtn_1_2,...
ImgBtn_2_1,ImgBtn_2_2,... )
But after I clicked on one of these Buttons
FindControl(ImgBtn_1_1),typeof(ImageButton) is null.
When i try to create a ImageButton with ID ImgBtn_1_1 there is a
Exeption because it's not unique. So my question is? ImgBtn_1_1 exists
but how can i get it. ctrlCurrImgBtn =
(ImageButton)Convert.ChangeType(FindControl(ImgBtn_1_1),typeof(ImageButton));
doesn,t work. There has to be another commande.
 
S

Scott Allen

The control IDs are not necessarily what you specify. The runtime can
add a prefix if you are inside of certain containers. If you have the
image buttons inside one of these containers, that would explain why
calling FindControl at the page level doesn't find the control.
See http://odetocode.com/Articles/116.aspx

--s
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top