Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Find controls without knowing the name

Find controls without knowing the name

Scheduled Pinned Locked Moved C#
helphtmldesign
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    coddyuk
    wrote on last edited by
    #1

    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.

    S 1 Reply Last reply
    0
    • C coddyuk

      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.

      S Offline
      S Offline
      sreejith ss nair
      wrote on last edited by
      #2

      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 **************************

      S C 2 Replies Last reply
      0
      • S sreejith ss nair

        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 **************************

        S Offline
        S Offline
        shambho
        wrote on last edited by
        #3

        I am sorry if i am wrong how can i know that its a Image control or image in a datagrid or some thing else. anand

        1 Reply Last reply
        0
        • S sreejith ss nair

          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 **************************

          C Offline
          C Offline
          coddyuk
          wrote on last edited by
          #4

          Hi S r e e j i t h N a i r Thanks but that didnt work either, I still only get the literals and the actual html form. :( I first knew I was dyslexic when I went to a Toga party as a goat.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups