server crashes when I access a certain control

  • Thread starter Thread starter Boban Dragojlovic
  • Start date Start date
B

Boban Dragojlovic

I have the following control defined (among others) ... it represents the
active form on the ASP

Protected WithEvents frmMain As System.Web.UI.HtmlControls.HtmlForm

Then I have this

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Page.IsPostBack Then
For Each ctl As WebControl In Me.frmMain.Controls
If ctl.CssClass = "FieldInError" Then
ctl.CssClass = ""
End If
Next
End If

End Sub



The "for each" loop is just designed to clear up any "highlighting" I may
have done during a previous round trip.

When this code is executed, the 'for each ....' statement crashes ASP.NET

The error in the Application Log says that it was recycled because it sucked
up too much memory. I watched it. It goes from 30k to 360k within a couple
of seconds.

I stepped through this code, and it never gets to the 'if ctl.cssClass'
statement ... it dies on the 'for each' statement.


Any ideas?
 
Most of the controls in the Controls collection are not going to be
WebControl so it would bomb. Get them as Control and then test for children
and is it a WebControl. You will have to step into the children to get the
controls say...under the HtmlForm control.

bill
 
Back
Top