Variable is used before it has been assigned

G

Guest

i have write code in that updates details of student and then present it in a
different panel i n the same. however a recieve object reference not set to
an instance of an object.

Can someone please help me to correct it. below is the sub where the error
is trapped.

Sub UpdateStudent_Click(ByVal sender As Object, ByVal e As EventArgs)
If Page.IsValid = True Then

Dim tbTitle As TextBox
Dim tbStatus As TextBox
Dim tbSurname As TextBox
Dim tbFirstname As TextBox
Dim tbHouseNumber As TextBox
Dim tbStreet As TextBox
Dim tbTown As TextBox
Dim tbCounty As TextBox
Dim tbCountry As TextBox
Dim tbPostCode As TextBox
Dim tbDateOfBirth As TextBox
Dim tbNationality As TextBox
Dim tbTelephone As TextBox
Dim tbMobile As TextBox
Dim tbEmail As TextBox
Dim tbFax As TextBox
Dim tbCourseID As TextBox
Dim tbDateEnroled As TextBox
Dim tbComment As TextBox

Dim item As DataListItem
For Each item In UpdateDataList.Items
tbTitle = item.FindControl("Title")
tbStatus = item.FindControl("Status")
tbSurname = item.FindControl("Surname")
tbFirstname = item.FindControl("Firstname")
tbHouseNumber = item.FindControl("HouseNumber")
tbStreet = item.FindControl("Street")
tbTown = item.FindControl("Town")
tbCounty = item.FindControl("County")
tbCountry = item.FindControl("Country")
tbPostCode = item.FindControl("Postcode")
tbDateOfBirth = item.FindControl("DateOfBirth")
tbNationality = item.FindControl("Nationality")
tbTelephone = item.FindControl("Telephone")
tbMobile = item.FindControl("Mobile")
tbEmail = item.FindControl("email")
tbFax = item.FindControl("Fax")
tbCourseID = item.FindControl("CourseID")
tbDateEnroled = item.FindControl("DateEnroled")
tbComment = item.FindControl("Comment")
Next item

Dim StudentID As Integer = CInt(ViewState("StudentID"))
Dim UpdateDetails As New StudentDB
UpdateDetails.UpdateStudentDetails(StudentID, tbTitle.Text,
tbSurname.Text, tbFirstname.Text, tbHouseNumber.Text, tbStreet.Text,
tbTown.Text, tbCounty.Text, tbCountry.Text, tbPostCode.Text,
tbDateOfBirth.Text, tbNationality.Text, tbTelephone.Text, tbMobile.Text,
tbEmail.Text, tbFax.Text, tbCourseID.Text, tbDateEnroled.Text, tbStatus.Text,
tbComment.Text)
BindViewPanel()
End If
End Sub
 
K

Karl Seguin [MVP]

I can't tell you how helpful it would be if you provided the exact line
where the error is at.

It might be because Items will hit the HeaderTemplate and FooterTemplate, in
which case there aren't any of the textbox you expect.

Karl
 
G

Guest

Thanks Karl. the exact line where i do get the error is:

UpdateDetails.UpdateStudentDetails(StudentID, tbTitle.Text,
tbSurname.Text.....tbComment.text)

in the code posted. This use to work well without any error when i send it
to a different page to display it result using request.redirect(url). Now
that i result to appear in a different panel in the same page it give me this
error. I need help
 
K

Karl Seguin [MVP]

Well, you'll need to debug your code. If findControl fails, it returns
null...so it could be any of them...a simple typo perhaps. If you have
visual studio, add a break point to the code and hit f5..then step through
it...

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top