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

  • Thread starter Thread starter flyingAway
  • Start date Start date
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
 
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.
 
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.
 
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
 
Back
Top