Jump to content
Sign in to follow this  
jjmendes

For each - Para Apagar controles

Recommended Posts

jjmendes

Ola Pessoal,

Gostaria de uma ajuda, para criar um for each , que irá pagar os textbox da página.

A página foi adicionada, como Web form Using Master Page.

Grato desde , já.

Share this post


Link to post
Share on other sites
newtoncw

Neste caso você não poderá utilizar o for each, pois a lista não pode ser modificada durante o for each (ou seja, adicionar e remover itens), desta forma terá de se usar o for "normal"

For i = Me.Page.Controls.Count - 1 To 0 Step -1
    Me.Page.Controls.RemoveAt(i)
End

Share this post


Link to post
Share on other sites
Tiago Salgado

Tenta algo assim:

foreach(Control c in Page.Controls)
{
    if(c.GetType() == typeof(TextBox))
    {
          ((TextBox)c).Text = string.Empty;
    }
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.