Find controls without knowing the name
-
Hi, I have a webform, which changes the cssclass of a textbox and displays and error marker if the fields were left blank, or wrong data inputted etc. For the reset button I would like to rack through the textboxes images within the form, and if the image is visible, turn it off etc. I could do this by hard coding each instance of the image, but was hoping there would be a tidier way of doing this. Here is what i have got already ... foreach(object myControl in Page.Controls) { if(myControl is System.Web.UI.WebControls.Image) { System.Web.UI.WebControls.Image errImage = (System.Web.UI.WebControls.Image)myControl; if(errImage.Visible == true) { errImage.Visible = false; } } However all i am getting is the Html form itself and 2 literals. I know im missing someting silly, but not sure what. Any help would be appreciated. Thanks I first realised I was dyslexic when I went to a Toga party dressed as a goat.
-
Hi, I have a webform, which changes the cssclass of a textbox and displays and error marker if the fields were left blank, or wrong data inputted etc. For the reset button I would like to rack through the textboxes images within the form, and if the image is visible, turn it off etc. I could do this by hard coding each instance of the image, but was hoping there would be a tidier way of doing this. Here is what i have got already ... foreach(object myControl in Page.Controls) { if(myControl is System.Web.UI.WebControls.Image) { System.Web.UI.WebControls.Image errImage = (System.Web.UI.WebControls.Image)myControl; if(errImage.Visible == true) { errImage.Visible = false; } } However all i am getting is the Html form itself and 2 literals. I know im missing someting silly, but not sure what. Any help would be appreciated. Thanks I first realised I was dyslexic when I went to a Toga party dressed as a goat.
hi, Try this, foreach(Control ctl in page.Controls) { Image Img= ctl as WebControls.Image; if(Img!=null) { //do your operations } } ************************** S r e e j i t h N a i r **************************
-
hi, Try this, foreach(Control ctl in page.Controls) { Image Img= ctl as WebControls.Image; if(Img!=null) { //do your operations } } ************************** S r e e j i t h N a i r **************************
-
hi, Try this, foreach(Control ctl in page.Controls) { Image Img= ctl as WebControls.Image; if(Img!=null) { //do your operations } } ************************** S r e e j i t h N a i r **************************