Object reference not set to an instance of an object 
Author Message
 Object reference not set to an instance of an object

HELLLP!

OK I give up, what am I not doing?

I have a web form with a listbox populated with the files from a folder.
When the user clicks a file then a button the file should begin downloading.
(I should mention I'm new to this web stuff)
Here's what I'm trying:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Try
Dim FileURL As String = "c:\inetpub\wwwroot\GMFileUpload\GMDownload\" &
FileList.SelectedItem.Text
Response.WriteFile(FileURL)

Catch
Response.Write("<script>" & vbCrLf)
Response.Write("alert('" & Err.Description & "');" & vbCrLf)
Response.Write("</script>" & vbCrLf)

End Try
End Sub

this spits back the error : "Object reference not set to an instance of an
object"

I had thought the server end isn't getting the selection, but if I set
autopostback on the listbox to true
the form refreshes and I loose the selection...
I'm sure it's an easy thing, but I can't figure it out without a few
pointers....

Jim



Sat, 26 Mar 2005 22:49:58 GMT  
 Object reference not set to an instance of an object
You can't use Err.Description

Try

Catch ex as Exception
Response.Write("<script>" & vbCrLf)
Response.Write("alert('" & ex.tostring & "');" & vbCrLf)
Response.Write("</script>" & vbCrLf)


HELLLP!

OK I give up, what am I not doing?

I have a web form with a listbox populated with the files from a folder.
When the user clicks a file then a button the file should begin downloading.
(I should mention I'm new to this web stuff)
Here's what I'm trying:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Try
Dim FileURL As String = "c:\inetpub\wwwroot\GMFileUpload\GMDownload\" &
FileList.SelectedItem.Text
Response.WriteFile(FileURL)

Catch
Response.Write("<script>" & vbCrLf)
Response.Write("alert('" & Err.Description & "');" & vbCrLf)
Response.Write("</script>" & vbCrLf)

End Try
End Sub

this spits back the error : "Object reference not set to an instance of an
object"

I had thought the server end isn't getting the selection, but if I set
autopostback on the listbox to true
the form refreshes and I loose the selection...
I'm sure it's an easy thing, but I can't figure it out without a few
pointers....

Jim



Sat, 26 Mar 2005 23:50:17 GMT  
 Object reference not set to an instance of an object
Thanks, I'll remember that in future.
But the problem was with -

Dim FileURL As String = "c:\inetpub\wwwroot\GMFileUpload\GMDownload\" &
FileList.SelectedItem.Text
Response.WriteFile(FileURL)

I added the try - catch in an attempt to see what was going on.

I couldn't figure out was I was doing wrong.
The penny finally dropped. I "wasn't" doing anything wrong

I was loading the listbox dynamically on the page_load event.
Eventually I discovered - that was too late,
The items showed on the page but weren't really there..... (figure that one
out)
When I moved the list populate routine to the page_init event everything
worked great.

What can I say... Timing is everything.......


You can't use Err.Description

Try

Catch ex as Exception
Response.Write("<script>" & vbCrLf)
Response.Write("alert('" & ex.tostring & "');" & vbCrLf)
Response.Write("</script>" & vbCrLf)



HELLLP!

OK I give up, what am I not doing?

I have a web form with a listbox populated with the files from a folder.
When the user clicks a file then a button the file should begin downloading.
(I should mention I'm new to this web stuff)
Here's what I'm trying:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Try
Dim FileURL As String = "c:\inetpub\wwwroot\GMFileUpload\GMDownload\" &
FileList.SelectedItem.Text
Response.WriteFile(FileURL)

Catch
Response.Write("<script>" & vbCrLf)
Response.Write("alert('" & Err.Description & "');" & vbCrLf)
Response.Write("</script>" & vbCrLf)

End Try
End Sub

this spits back the error : "Object reference not set to an instance of an
object"

I had thought the server end isn't getting the selection, but if I set
autopostback on the listbox to true
the form refreshes and I loose the selection...
I'm sure it's an easy thing, but I can't figure it out without a few
pointers....

Jim



Sun, 27 Mar 2005 21:11:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Multiple Forms Question: Object reference not set to an instance of an object

2. Error when showing form: Object reference not set to an instance of an object

3. Object Reference Not Set to an Instance of an Object

4. Please help with error: Object reference not set to an instance of an object

5. How to fix Error: Object reference not set to an instance of an object

6. Object reference not set to the instance of an object

7. Object reference not set to an instance of an object

8. Object reference not set to an instance of an object

9. Object reference not set to an instance of an object

10. New Twist on: Object reference not set to an instance of an object

11. Object reference not set to an instance of an object

12. Error: Object reference not set to an instance of an object

 

 
Powered by phpBB® Forum Software