.NET Questions (CLOSED)

Questions and Answers on any aspect of .NET. Now closed.

This discussion group is now closed.

Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day.

The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too.

Determining a Control's Type

I thought this would be easy, but...

I am looping through all the controls in a collection, and I want to reset each of them, depending on the type. So, I have the following code:

For Each oControl As Control In Me.pnlForm.Controls
  If oControl.GetType.ToString = "System.Web.UI.WebControls.TextBox" Then
    CType(oControl, System.Web.UI.WebControls.TextBox).Text = ""
  End If

Is there a better way than the conversion of GetType to a string?  If I just try a comparison between oControl.GetType and System.Web.UI.WebControls.Textbox, I get an error message saying 'TextBox' is a type in 'WebControls' and cannot be used in an expression.
Ken Send private email
Friday, July 21, 2006
You can use the TypeOf function to compare a control's type in VB.NET


If TypeOf MyControl Is TextBox Then

End If

Friday, July 21, 2006
Perfect - thank you.
Ken Send private email
Friday, July 21, 2006

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz