Last post Nov 09, 2017 08:56 AM by asptred
Nov 08, 2017 03:09 PM|asptred|LINK
I have class that create a button for modify data in a database. This button is linked to a block of a controls that have textbox and label created dynamically. Now i have a lot of this blocks of controls, and if i want to modify a field in db, i write what
i want in this text box and then i click on modify button for update only the row of the controls block. I have done all of this but when i want to get the text only from a block of controls with Control.FindContrl(id), the method find 0 controls, and if i
use Control.FindControl("ct100$Contenuto_Principale$"+id) find all what i want. This is the code of the event
Page controllo = HttpContext.Current.Handler as Page;
for (int i = 0; i < lista.Count; i++)
Control control = controllo.FindControl("ctl00$Contenuto_Principale$"+lista[i]); //lista is a list of string created before with the id of controls and passed as a parameters in another file
if (control is TextBox)
My question is, can i get --> ctl00$Contenuto_Principale$ with a method for use it in all the page?
Nov 08, 2017 07:10 PM|DA924|LINK
I suggest that you use the F12 Developer Tools in IE particularly the DOM Explorer that allows you to highlight a control showing on the page to see the actual attribute value like ID value at time of display so you can see the ID value of the control you
are trying to find, which is shown in the F12 pane.
Nov 09, 2017 07:59 AM|asptred|LINK
ok but i want to get dynamically that part and, considering that i take the controls in other .cs file so i get the page as an object, but this object have only the name of the controls, so i cant use the id's, because they haven't it, and if you see the
code, there are a list named lista that contain the id's of the controls and this list is created before in another page and passed through parameters.
Nov 09, 2017 08:18 AM|Eric Du|LINK
According to your description and code, I think you want to get the textbox text through id, but your controls are dynamically created, so ID also is dynamically.
I want to explain to you about ctl00$Contenuto_Principale$, maybe it is parent control or content page ID, you say want this code work for all page, but different
page with different control's ID, if you want to write a function to accept the ID parameter, then found the control(like textbox) through ID?
If my understanding is right, please tell me!
Also i think if you want to get child control through id, i think you could set
of textbox, then you could get the control through id directly. Like this:
<asp:TextBox ID="TextBox1" runat="server" ClientIDMode="Static"></asp:TextBox>
Nov 09, 2017 08:56 AM|asptred|LINK
I already set the ClientIDMode on static but i dont know why the page have only the name in the form. This is the screen of parameters of the page
i don't remeber if in this window there must be the id's, anyway i don't see it here. This is the code of the class that create the textbox:
protected TextBox textBox = new TextBox();
public TextBoxP(string testo, string classe, string titolo, string id)
this.textBox.Attributes["Class"] = classe;
this.textBox.Attributes["Placeholder"] = titolo;
this.textBox.ID = id;
this.textBox.Text = testo;
public TextBox GetTextBox()
public void addCssClass(string classe)
this.textBox.Attributes["Class"] += " " +classe;
public string getId()