473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

button click clears textbox and returns null error

I am trying to follow the instructions from
http://authors.aspalliance.com/das/t...ileupload.aspx to upload a
file.

The webform contains 2 buttons and a textbox. Browse for a file, click the
Upload button and it's supposed to save it somewhere.

Problem is, when browse for a file and click the Upload button, the textbox
get cleared out and the page refreshes. No save action occurs.

Here's the code:

Sub Upload(ByVal Source As Object, ByVal e As EventArgs)
If Not (myFile.PostedFile Is Nothing) Then
Dim intFileNameLength As Integer
Dim strFileNamePath As String
Dim strFileNameOnly As String
'Logic to find the FileName (excluding the path)
strFileNamePath = myFile.PostedFile.FileName
intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\")
strFileNameOnly = Mid(strFileNamePath, _
(Len(strFileNamePath) - intFileNameLength) + 2)
myFile.PostedFile.SaveAs _
("c:\inetpub\wwwroot\yourwebapp\upload\" & strFileNameOnly)
lblMsg.Text = "File Upload Success."
End If
End Sub

with the SaveAs location changed for my system.

I doubt the code has a problem. If I comment out the "If Not
(myFile.PostedFile Is Nothing) Then" I get an
error:

"Object reference not set to an instance of an object"
and the "strFileNamePath = myFile.PostedFile.FileName" is highlighted.

The textbox is then cleared out. Why in the world is the textbox getting
cleared out every time?

Last time something like this happened it was because I turned Viewstate
off. However, enableViewstate is True for this webform.

Anybody know why the textbox is getting cleared out every time?

Thanks.

Nov 18 '05 #1
2 2967
it seems to be working. I tried it again from scratch.
"Tim Zych" <tzych@noworms_earth_link.dott.net> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
I am trying to follow the instructions from
http://authors.aspalliance.com/das/t...ileupload.aspx to upload a
file.

The webform contains 2 buttons and a textbox. Browse for a file, click the
Upload button and it's supposed to save it somewhere.

Problem is, when browse for a file and click the Upload button, the textbox get cleared out and the page refreshes. No save action occurs.

Here's the code:

Sub Upload(ByVal Source As Object, ByVal e As EventArgs)
If Not (myFile.PostedFile Is Nothing) Then
Dim intFileNameLength As Integer
Dim strFileNamePath As String
Dim strFileNameOnly As String
'Logic to find the FileName (excluding the path)
strFileNamePath = myFile.PostedFile.FileName
intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\")
strFileNameOnly = Mid(strFileNamePath, _
(Len(strFileNamePath) - intFileNameLength) + 2)
myFile.PostedFile.SaveAs _
("c:\inetpub\wwwroot\yourwebapp\upload\" & strFileNameOnly) lblMsg.Text = "File Upload Success."
End If
End Sub

with the SaveAs location changed for my system.

I doubt the code has a problem. If I comment out the "If Not
(myFile.PostedFile Is Nothing) Then" I get an
error:

"Object reference not set to an instance of an object"
and the "strFileNamePath = myFile.PostedFile.FileName" is highlighted.

The textbox is then cleared out. Why in the world is the textbox getting
cleared out every time?

Last time something like this happened it was because I turned Viewstate
off. However, enableViewstate is True for this webform.

Anybody know why the textbox is getting cleared out every time?

Thanks.


Nov 18 '05 #2
There is a default limit to the file size (2 MB) that can be uploaded. If you need to upload a file or more than the defaul then you can over ride it in the Web.Config file.

Something like the
<?xml version="1.0" encoding="utf-8" ?><configuration><system.web><!-- DYNAMIC DEBUG COMPILATIO
<httpRuntime maxRequestLength="20480"/
20MB * 1024 Max File Site has been Set Her
--

20 MB - Yeah this site allows for huge file uploads. Engg Diagrams in PDF Format :

HT

Trevor Benedict
MCS

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Philip Townsend | last post by:
I have an aspx page that contains 2 user controls, each containing a seperate textbox and button. I would like to specify that one of the buttons recieve focus when the page loads. Also, I would...
29
by: Tom wilson | last post by:
I can't believe this is such an impossibility... I have an asp.net page. It accepts data through on form fields and includes a submit button. The page loads up and you fill out some stuff. ...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
7
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently...
1
by: Stephen D Cook | last post by:
What I am trying to do is have a set of option buttons which are required to click one. If the person doesn't click any before insert, they get an error. If they do click one, it inserts into the...
21
by: Ben | last post by:
Hello I have frames set up in an asp.net application and need one frame to refresh another. Seeing as events need to be registered at the time the page is sent from the server, I was wondering...
5
by: iDaz | last post by:
hello! i have a textbox, and 2 buttons. this is what i would like: when i click button 1, "1" is added to the textbox. when i click button 2, "2" is added to the textbox. i have tried to do...
2
by: mturner64 | last post by:
Good Day! I am fairly new to asp.net. I am using Microsoft VWD 2008 express edition. I have linked an Access 2007 database to my asp.net application using a gridview control. On the webpage are...
3
by: mturner64 | last post by:
I am using Microsoft VWD 2008 express edition. I have linked an Access 2007 database to my asp.net application using a gridview control. On the webpage are four text boxes allowing a user to input...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.