How to Find Control in a page which is inherited from MasterPage
-
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
-
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
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
-
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
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
-
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
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.
-
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
Plz try using "ctl00$CphAdmin$TextBox" instead of "ctl00_CphAdmin_TextBox"