This might be a noob question but I couldn't understand why it didn't work. I want to clear all the forms inside the page after the user has entered a new record. I call it right before my OnClick
method finishes. My page also does not have a parent Master page
and I just want to iterate over the Controls
I want, not all. This is my code:
(I know that if I use it like this it will mess with the DropDownList items, I will change it after I get the logic of getting the controls in page)
public void ClearForms()
{
foreach (var item in Page.Controls)
{
if (item is TextBox)
{
((TextBox)item).Text = String.Empty;
}
if (item is ListItem)
{
((ListItem)item).Text = "Choose...";
((ListItem)item).Value = "-1";
}
}
}
The program also does not go inside the if
statements. I tried to get type by item.GetType()
but it said it wasn't valid in the context.