Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

How do I reference the fileuploader, trying to make msgbox appeaer if fileuploader hasnt been submitted

I currently use this when one of  my dropdowns hasnt be selected. Now I need to be able to stop the user from submitting a request if the attachment hasnt been attached and the path is still visible in the uploader. I was going for an onlick if uploader is not blank then msgbox popup. The problem is I dont know how to reference the uploader. .Text .Value or another way? This is my attempt...

All help much appreciated
btnSubmit.Attributes.Add("onclick", "if(document.getElementById('FileUploadControl').text!='') {window.alert('Please submit your attachment before submitting request');return false;}");

Open in new window

0
dwezil
Asked:
dwezil
  • 4
  • 4
4 Solutions
 
TimCotteeHead of Software ServicesCommented:
Hello dwezil,

It is the .value property, however there is no guarantee that this will actually work. In IE it does if you allow active scripting that IE7 blocks. In firefox it doesn't seem to work at all. The reason for this is that access to that control is strictly controlled, in theory you should have no access to it (certainly no ability to write a value in there) and as I say there is no guarantee that client-side script will be able to access the .value property correctly on all browsers.

Regards,

TimCottee
0
 
dwezilAuthor Commented:
well could i possibly create a text box that mirrors the text in the uploader and set the msgbox to react to whether that text box has text or not?
0
 
TimCotteeHead of Software ServicesCommented:
dwezil,

On the same basis, if you cannot access the property then you cannot mirror it. This is a case where your only recourse is to handle this in server-side validation rather than client-side.

TimCottee
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
dwezilAuthor Commented:
thats annoying, I thought it would have been a simple thing to do
0
 
TimCotteeHead of Software ServicesCommented:
dwezil,

Indeed, it is a security thing though. Because that control is allowed access to the client's file system it poses a security risk as such it has been "locked down" in such a way to prevent any access to it with script. There is an obvious reason for this, if you could access that value easily and change it to a specific file you would then be able to silently upload any file from the client's machine to your server thus potentially compromising any system that viewed your page.

I understand the problem though and it is one that afflicts all of us.

TimCottee
0
 
dwezilAuthor Commented:
not even FileUploadControl.HasFile. Im clutching at straws here
0
 
TimCotteeHead of Software ServicesCommented:
dwezil,

Server-side that is, and there it is no problem at all. It is simply the ability to interact with the control on the client-side that is severely restricted for security purposes. Once a user has selected a file and submitted the form then you can use .Hasfile etc in your server-side code quite happily. Of course the only problem with that is that you cannot prepopulate the fileupload element with the previously selected file name if it fails validation and is returned to the client.

TimCottee
0
 
dwezilAuthor Commented:
Thanks for your help Tim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now