Force Postback on FileUpload control

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2007
Posts: 291
Reputation: ericstenson is an unknown quantity at this point 
Solved Threads: 29
Team Colleague
ericstenson's Avatar
ericstenson ericstenson is offline Offline
Posting Whiz in Training

Force Postback on FileUpload control

 
0
  #1
Mar 4th, 2008
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."
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Force Postback on FileUpload control

 
0
  #2
Mar 4th, 2008
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:
  1. function detectFile()
  2. {
  3. var idval = document.getElementById("servercontrol").value;
  4.  
  5. if (idval.length > 5)
  6. {
  7. if (idval.indexOf(":") && idval.indexOf(".")
  8. {
  9. document.getElementById("serversubmitbtn").click();
  10. }
  11. }
  12. }
  13.  
  14. 'put attributes on it:
  15. ctrl.Attributes.Add("OnChange","retun detectFile()")
  16.  
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 291
Reputation: ericstenson is an unknown quantity at this point 
Solved Threads: 29
Team Colleague
ericstenson's Avatar
ericstenson ericstenson is offline Offline
Posting Whiz in Training

Re: Force Postback on FileUpload control

 
0
  #3
Mar 4th, 2008
You are awsome.
--
"Dummy."
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1
Reputation: hapdx is an unknown quantity at this point 
Solved Threads: 0
hapdx hapdx is offline Offline
Newbie Poster

Re: Force Postback on FileUpload control

 
0
  #4
Jan 20th, 2009
Originally Posted by SheSaidImaPregy View Post
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:
  1. function detectFile()
  2. {
  3. var idval = document.getElementById("servercontrol").value;
  4.  
  5. if (idval.length > 5)
  6. {
  7. if (idval.indexOf(":") && idval.indexOf(".")
  8. {
  9. document.getElementById("serversubmitbtn").click();
  10. }
  11. }
  12. }
  13.  
  14. 'put attributes on it:
  15. ctrl.Attributes.Add("OnChange","retun detectFile()")
  16.  
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.
Can help me a bit for using this Java code. It looks very useful! We use VB.NET and how do I integrate your code with our FileUpload1 control on our page. Do we need to integrate your script with a button also? Please explain. Thank you!!!
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Force Postback on FileUpload control

 
0
  #5
Jan 21st, 2009
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:

  1. document.getElementById("<%= ServerControl.ClientID %>");
I answer pm's.
I answer questions.
I answer quickly.
I answer.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC