[RESOLVED] Locate Object reference not set?
HI,
I keep getting this error -
"Object reference not set to an instance of an object"
Does anyone know how to trap the exact error location, or at least get a more informative error message?
Here is an example of my code where the error seems to be happening but everything looks okay to me
VB Code:
Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
Dim sMsg As String = ""
Try
If LCase(txtEdit.Text) = "true" Then
Response.Redirect("complete.aspx?display=pro_edit")
End If
Catch ex As Exception
' Record any exceptions and exit
sMsg = "The following exception occurred: Submit<br />" + ex.Message.ToString
End Try
If sMsg <> "" Then
Message.Visible = True
Message.Text = sMsg.ToString
End If
End Sub
Cheers Al
Re: Locate Object reference not set?
1) Just set a breakpoint in your code where ever the error is occurring.
2) Don't use LCase, use txtEdit.Text.ToLower
3) and change this
VB Code:
If sMsg <> "" Then
[color=red]To this[/color]
If sMsg.Length > 0 Then
Re: Locate Object reference not set?
Memnoch1207,
Thanks for that and thanks for the tips
If I want to lowercase and trim can I call as follows -
VB Code:
sUsername = Username.Text.Trim.ToLower
Does this work with the querystring? I'm getting yet another object ref error
VB Code:
If Request.QueryString("edit").ToLower = "true" And iUserID > 0 Then
Cheers Al