| | |
Force Postback on FileUpload control
Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved |
Hi - I was wondering if there is a way to force a postback after the FileUpload1 control has a file... Right now, people his "Browse" select the file then click another button to upload the file. I want to write code on postback to automatically write the file to the server, so I would like to cause a postback event when it has a file... any idea how to do this?
--
"Dummy."
"Dummy."
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
You cannot detect when it has a file, however you can detect length. If you wish to detect length, you need to make sure the box is READONLY. Cause, like me and probably a few others, I type most of my paths into the upload box. This you would have to do client side, so javascript would be best bet. Something like this:
Now you need a button with this one, and you should always have it just incase javascript is disabled. What this does is checks to see if the length of your file upload control is greater than 5 (C:/ & .tag is easily over 5 combined, let alone the actual file name), if it is, it then checks to make sure that there is at least a colon and a period. You can change this extensively and use regex if you wish. Then it calls your submit button's onclick attribute dynamically.
ASP.NET Syntax (Toggle Plain Text)
function detectFile() { var idval = document.getElementById("servercontrol").value; if (idval.length > 5) { if (idval.indexOf(":") && idval.indexOf(".") { document.getElementById("serversubmitbtn").click(); } } } 'put attributes on it: ctrl.Attributes.Add("OnChange","retun detectFile()")
•
•
Join Date: Jan 2009
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
You cannot detect when it has a file, however you can detect length. If you wish to detect length, you need to make sure the box is READONLY. Cause, like me and probably a few others, I type most of my paths into the upload box. This you would have to do client side, so javascript would be best bet. Something like this:
Now you need a button with this one, and you should always have it just incase javascript is disabled. What this does is checks to see if the length of your file upload control is greater than 5 (C:/ & .tag is easily over 5 combined, let alone the actual file name), if it is, it then checks to make sure that there is at least a colon and a period. You can change this extensively and use regex if you wish. Then it calls your submit button's onclick attribute dynamically.ASP.NET Syntax (Toggle Plain Text)
function detectFile() { var idval = document.getElementById("servercontrol").value; if (idval.length > 5) { if (idval.indexOf(":") && idval.indexOf(".") { document.getElementById("serversubmitbtn").click(); } } } 'put attributes on it: ctrl.Attributes.Add("OnChange","retun detectFile()")
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
That code is javascript, so it is independent of any language run on the server. Now where it says "serversubmitbtn" or "servercontrol", you will want to put the ID of the server control right there. A method for this follows:
VB Syntax (Toggle Plain Text)
document.getElementById("<%= ServerControl.ClientID %>");
I answer pm's.
I answer questions.
I answer quickly.
I answer.
I answer questions.
I answer quickly.
I answer.
![]() |
Other Threads in the ASP.NET Forum
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox click commonfunctions control css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iframe iis javascript listbox login microsoft mono mouse mssql multistepregistration news novell numerical objects opera panelmasterpagebuttoncontrols radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visualstudio web webapplications webdevelopemnt webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers






