WebForm read

  • Thread starter Thread starter italo
  • Start date Start date
I

italo

Hi,

Is there a way to read witch WebControl (like TextBox's) and howmany
webcontrols are in a WebForm?
 
Well yes. Typically you can reference a control by it's ID, so if you
have a textbox webcontrol on the page that's id is txtFirstBox, you can
reference that control by that name. For instance you can access the
text property of the text box by txtFirstBox.Text.

Another way you can access a control on the page is through the find
command. You can do this like so - Page.FindControl("controlname").

This is how you can find controls that are in the page collection
(finding controls contained in other web controls can be found in a
similar manner).

You can access how many web controls are on the page through
Page.Controls.Count.

Hope this helps,
Darren Kopp
 
Thank you Darren.. a half of my doubts are ok.

Can i put in a Label, for example, the numbers of TextBox in a
WebForm??
if yes, how can i do this?

im sorry if its a Newbie question :)

Great Regards.
Italo Mácola
 
Thats it :)
we found a way to do it. with FindControl and Controls.
its in C#, im counting the number of TextBox's and cleaning them.
i think its okai.

Control frm = new Control();
frm = Page.FindControl("Form1");
int i = 0;
foreach (Control clt in frm.Controls)
{
i += 1;
TextBox tb = new TextBox();
if (clt is TextBox)
{
tb = (TextBox)clt;
tb.Text = "";
}
}

thank you for your help one more time ;)

King Regards.
Italo Mácola
 
Back
Top