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. Web Development
  3. ASP.NET
  4. How to Find Control in a page which is inherited from MasterPage

How to Find Control in a page which is inherited from MasterPage

Scheduled Pinned Locked Moved ASP.NET
helptutorial
5 Posts 5 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.
  • K Offline
    K Offline
    Kuricheti
    wrote on last edited by
    #1

    Hi, I have one master page and one default.aspx page inherted from master page. Now My Default page has 10 TextBox controls with ID's 'Textbox1','Textbox2',.......'Textbox10' and one Button. In th button click event I want to catch these textboxes dynamically like for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl("TextBox"+i); } I saw the viewsource all controlId's are replaced like "ctl00_CphAdmin_TextBox1". even I tried like for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl("ctl00_CphAdmin_TextBox"+i); } But not worked .........can any body help me the way to acheive this. Thnaks Hari

    S R F V 4 Replies Last reply
    0
    • K Kuricheti

      Hi, I have one master page and one default.aspx page inherted from master page. Now My Default page has 10 TextBox controls with ID's 'Textbox1','Textbox2',.......'Textbox10' and one Button. In th button click event I want to catch these textboxes dynamically like for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl("TextBox"+i); } I saw the viewsource all controlId's are replaced like "ctl00_CphAdmin_TextBox1". even I tried like for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl("ctl00_CphAdmin_TextBox"+i); } But not worked .........can any body help me the way to acheive this. Thnaks Hari

      S Offline
      S Offline
      Sun Rays
      wrote on last edited by
      #2

      Hi, if your textboxes are in any other control like panel then you have to search panel first and then you have to search textboxes in panel. Else here,

      Kuricheti wrote:

      for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl("TextBox"+i); }

      for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl("TextBox"+i.ToString()); }

      Thanks, Sun Rays To get something you must have to try once. My Articles

      1 Reply Last reply
      0
      • K Kuricheti

        Hi, I have one master page and one default.aspx page inherted from master page. Now My Default page has 10 TextBox controls with ID's 'Textbox1','Textbox2',.......'Textbox10' and one Button. In th button click event I want to catch these textboxes dynamically like for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl("TextBox"+i); } I saw the viewsource all controlId's are replaced like "ctl00_CphAdmin_TextBox1". even I tried like for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl("ctl00_CphAdmin_TextBox"+i); } But not worked .........can any body help me the way to acheive this. Thnaks Hari

        R Offline
        R Offline
        Rajesh_K_Sharma
        wrote on last edited by
        #3

        Hi Kuricheti try this code , i think this will help you. protected void Button1_Click(object sender, EventArgs e) { GetControlval(this.Controls); } public void GetControlval(ControlCollection Controlcol) { string strTextBox; foreach (System.Web.UI.Control ctl in Controlcol) { if (ctl != null) { if (ctl.ToString().ToLower().EndsWith("textbox")) strTextBox = ((System.Web.UI.WebControls.TextBox)ctl).Text; } if (ctl.HasControls()) { GetControlval(ctl.Controls ); } } }

        rajesh

        1 Reply Last reply
        0
        • K Kuricheti

          Hi, I have one master page and one default.aspx page inherted from master page. Now My Default page has 10 TextBox controls with ID's 'Textbox1','Textbox2',.......'Textbox10' and one Button. In th button click event I want to catch these textboxes dynamically like for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl("TextBox"+i); } I saw the viewsource all controlId's are replaced like "ctl00_CphAdmin_TextBox1". even I tried like for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl("ctl00_CphAdmin_TextBox"+i); } But not worked .........can any body help me the way to acheive this. Thnaks Hari

          F Offline
          F Offline
          firozu
          wrote on last edited by
          #4

          Kuricheti wrote:

          for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl("TextBox"+i); }

          Try using -- for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl(this.ClientID + "TextBox"+i); } OR for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl(this.ClientID + "_TextBox"+i); } Hope this works for you.

          1 Reply Last reply
          0
          • K Kuricheti

            Hi, I have one master page and one default.aspx page inherted from master page. Now My Default page has 10 TextBox controls with ID's 'Textbox1','Textbox2',.......'Textbox10' and one Button. In th button click event I want to catch these textboxes dynamically like for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl("TextBox"+i); } I saw the viewsource all controlId's are replaced like "ctl00_CphAdmin_TextBox1". even I tried like for(int i=1;i<=10;i++) { (TextBox) txt = (TextBox)FindControl("ctl00_CphAdmin_TextBox"+i); } But not worked .........can any body help me the way to acheive this. Thnaks Hari

            V Offline
            V Offline
            vincyjinoy
            wrote on last edited by
            #5

            Plz try using "ctl00$CphAdmin$TextBox" instead of "ctl00_CphAdmin_TextBox"

            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