Questions and Answers on any aspect of .NET. Now closed.
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 = ""
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.
You can use the TypeOf function to compare a control's type in VB.NET
If TypeOf MyControl Is TextBox Then
Friday, July 21, 2006
This topic is archived. No further replies will be accepted.Other recent topics
Powered by FogBugz