Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm working on an ASP page that will search for a book by title, author, subject, or keywords. I created variables to hold the information, but when I debug the page, I get a NullReferenceException:

Object reference not set to an instance of an object

How do you reference a string to a textbox? What else should I do to my variables? I hopethis revised code helps.

VB
Public Class Search
	Inherits System.Web.UI.Page

	Dim strTitle As String = Me.TB_Title.Text
	Dim strAuthor As String = Me.TB_Author.Text
	Dim strSubject As String = Me.TB_Subject.Text
	Dim strKeywords As String = Me.TB_Keyword.Text

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

	End Sub

	Protected Sub BTN_Submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BTN_Submit.Click
		If TB_Title.Text = "" And TB_Author.Text = "" And TB_Subject.Text = "" And TB_Keyword.Text = "" Then
			CV_BlankField.Visible = True
		Else
			CV_BlankField.Visible = False
		End If
	End Sub

	Protected Sub BTN_Clear_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BTN_Clear.Click
		strTitle = ""
		strAuthor = ""
		strSubject = ""
		strKeywords = ""
	End Sub
End Class
Posted
Updated 10-Oct-11 11:18am
v2
Comments
Herman<T>.Instance 10-Oct-11 0:39am    
in what event/method was this code placed?
Herman<T>.Instance 10-Oct-11 15:48pm    
still a problem?
Blind.Geek81 10-Oct-11 19:40pm    
I put them above all of my methods so they would be global.

1 solution

I added session states for all my controls, but I still have 40 errors. Time for a new question :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900