Web Page Controls

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

How can I step through all of the controls I've placed on a web page and
identify properties for each control.

For example:

I'd like to find all "TextBox" controls and its "ReadOnly" property setting
and the "Value" in the control. Also, what is the general rule for checking
other properties for the control.

Thanks,
 
How can I step through all of the controls I've placed on a web page and
identify properties for each control.

For example:

I'd like to find all "TextBox" controls and its "ReadOnly" property
setting
and the "Value" in the control. Also, what is the general rule for
checking
other properties for the control.

You might have better luck asking in
microsoft.public.dotnet.framework.aspnet.
 
Greg said:
How can I step through all of the controls I've placed on a web page and
identify properties for each control.

For example:

I'd like to find all "TextBox" controls and its "ReadOnly" property
setting
and the "Value" in the control. Also, what is the general rule for
checking
other properties for the control.

You can write a recursive method that iterates over the Controls collection
finding all the controls of the type you want.

private void SetAllTextBoxesToReadOnly(Control container)
{
if (container is TextBox)
{
((TextBox)container).ReadOnly=true;
}
else
{
foreach (Control c in container.Controls)
{
SetAllTextBoxesToReadOnly(c);
}
}
}

Then, invoke the method by passing a container that is the root for the
controls that you want to examine. For example, if you are placing all your
page content inside a <div>, change the div to <div id="myRoot"
runat="server"> and then invoke the method like this:

SetAllTextBoxesToReadOnly(myRoot);
 
Back
Top