VB.NET - QueryString ? VB.NET - Asked By Eric Smith on 02-Nov-06 12:49 PM

I am trying to pass a value from txtSearch.Text in a web form named EditAptDetails.aspx  to another web form named  frmCreateAptForExistingClient.aspx, and then display the value being passed in the textbox named txtPhone.Text

Here is the code that I am using

' Pass value of txtSearch.text to another page
Response.Redirect("frmCreateAptForExistingClient.aspx?Parameter=" + txtSearch.Text)

'Receive value from another page and display in txtPhone.Text
Private
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

         txtPhone.Text = Request.QueryString("Parameter").ToString()

End Sub

System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 26:     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Line 27:         'Put user code to initialize the page here
Line 28:         txtPhone.Text = Request.QueryString("Parameter").ToString()
Line 29:     End Sub
Line 30: 

Remove ToString() - F Cali replied to Eric Smith on 02-Nov-06 12:56 PM

Try removing the ToString() part and see if the error goes away.  Also there is no need to call ToString() because QueryString will already return a string.

txtPhone.Text = Request.QueryString("Parameter")

use this - Sachin Mishra replied to Eric Smith on 02-Nov-06 01:24 PM

string val = txtSearch.Text

Server.Transfer("frmCreateAptForExistingClient.aspx?Parameter=" +val  );

txtPhone.Text = Request.QueryString("Parameter").ToString()

Sushila Patel replied to Eric Smith on 02-Nov-06 02:36 PM

 txtPhone.Text = Request("Parameter") 'Here try changing the name Parameter to "param" make sure to do this when you pass the variable too

Also make sure there is value in the txtSearch

I suspect, regardless of the well-intentioned - Peter Bromberg replied to Eric Smith on 02-Nov-06 03:34 PM

responses, that the issue is that your txtSearch.Text property you are using to populate the value portion of the ?Parameter=  querystring value is null.  It is always a good idea to check for null before attempting to use a value anyway. It prevents exceptions, which are expensive to process and cause ugly yellow and red error pages. e.g.,

if Request.QueryString("Parameter") is not Nothing then
' rest of your code here that gets the value and uses it
end if




System.NullReferenceException - Robbe Morris replied to Peter Bromberg on 02-Nov-06 04:25 PM

Suppose when he saw this on the screen shot he posted that he thought .net

was just lying to him???

Thanks for bringing a little sobriety to this thread.

Sometimes it takes a real effort - Peter Bromberg replied to Robbe Morris on 02-Nov-06 05:03 PM

to see the obvious, and take exception messages at face value.


just this will do - gagan kopparam replied to Eric Smith on 07-Nov-06 01:13 PM

if Request.("Parameter")<> Nothing then

      txtPhone.Text =Request.("Parameter")

end if