-
Error when trying to loop through Form Controls
I have a current form that has some code on the Submit_Click event and I recently added a Class reference at the top to validate the controls and if they fail highlight them. But now when i run the form it fails when it runs the following code:
Sub Submit_Click(sender As Object, e As EventArgs)
If Page.IsValid then
Dim myForm As Control = Page.FindControl("security")
Dim ctl1 As Control
For Each ctl1 In myForm.Controls
If ctl1.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox") Then
If CType(ctl1, TextBox).text = "" Then
AutoEmail1.Ignorefieldlist += CType(ctl1, TextBox).id+","
Else
CType(ctl1, TextBox).Text = "I Ran"
End If
End If
Next ctl1
AutoEmail1.Initiate()
End if
End Sub
It fails specifically on the For Each line. The error i get is:
Object reference not set to an instance of an object.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Is there a different way i have to write the syntax now for looping through the controls if im using a class to do some validation of them?
-
Sounds like this line is failing:
Dim myForm As Control = Page.FindControl("security")
Are you sure that FindControl is returning a reference to your form?
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
EDIT: I fixed it, i had to add ID="myformname" to the form tag..
Chris
Last edited by oochr1soo; 09-16-2005 at 03:43 PM.
Similar Threads
-
By bit_ravinder in forum .NET
Replies: 0
Last Post: 07-13-2005, 01:22 AM
-
By Kee Peck in forum ASP.NET
Replies: 2
Last Post: 05-23-2002, 12:35 PM
-
Replies: 1
Last Post: 05-23-2002, 12:07 PM
-
Replies: 1
Last Post: 03-25-2002, 12:48 PM
-
By Brian in forum authorevents.mitchell
Replies: 1
Last Post: 10-16-2000, 09:24 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks