Does anyone see why I would get this error? Object not set to an instance of an object
Here is my code and I get the error on the DirectCast line.
I have 5 labels on my pae Label1, label2, label3, label4, label5.
Dim responseStream As Stream = theResponse.GetResponseStream()
Dim streamReader As StreamReader = New StreamReader(responseStream)
Dim responseText As String = streamReader.ReadToEnd
Dim contents As String = responseText.ToString
If contents.Length = 0 Then Exit Function
Dim i As Integer = 0
Dim intCount As Integer = 0
Dim emails As String()
Dim email As String
Dim results As New StringBuilder
emails = ExtractEmailAddressesFromString(contents)
For i = 1 To 5
For Each email In emails
intCount += 1
results.Append(email & vbNewLine)
Next
DirectCast(FindControl(String.Format("Label{0}", CStr(i))), Label).Text = strURI.Substring(strURI.ToString().LastIndexOf("/") + 1) & ": " & intCount.ToString()
Next
Here is my code and I get the error on the DirectCast line.
I have 5 labels on my pae Label1, label2, label3, label4, label5.
Dim responseStream As Stream = theResponse.GetResponseStream()
Dim streamReader As StreamReader = New StreamReader(responseStream)
Dim responseText As String = streamReader.ReadToEnd
Dim contents As String = responseText.ToString
If contents.Length = 0 Then Exit Function
Dim i As Integer = 0
Dim intCount As Integer = 0
Dim emails As String()
Dim email As String
Dim results As New StringBuilder
emails = ExtractEmailAddressesFromString(contents)
For i = 1 To 5
For Each email In emails
intCount += 1
results.Append(email & vbNewLine)
Next
DirectCast(FindControl(String.Format("Label{0}", CStr(i))), Label).Text = strURI.Substring(strURI.ToString().LastIndexOf("/") + 1) & ": " & intCount.ToString()
Next