The code given is actually an aspx page. Only the content inside the <html></html> is given.
Can you be a bit more specific about what you want to achieve? Do you want your customized fileupload on the master, child?
How do you want to customize it etc.
Did you try to add the above code to your application?
Do you get errors, what goes wrong?
Kind regards,
Wim
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
sorry for repeating it is my mistake sorry but i want to use upload file as standard not input becouse this control in about 40 page and i can't change the code from start again so try to help me [:)]
The code posted by Win should work... the really issue here is What will we do with the file (file path or file name)?
Post a file in a server is a little bit complicated, going on a step forward (after we get the file name in some way)... How do we post the file to the server? The HTTPPostedFile class has its "FileName" property as "Read Only", also the "FileName" property
of the UploadFile control... I spent a little time trying and finally I had to use the UploadFile as it. I improve a little the interface using this version of an UploadFile
http://en.fileuploadajax.subgurim.net/ works fine, and so far it results stable.
look Wim that is the code I write it and it doesn't work see it and replay me ok thx .
Hi ahmed,
You're right about the code not working ....
The cause of this is the document.getElementById. On a masterPage, when the page gets rendered to be displayed (meaning the master and content-page will merge) the ID's of the controls get a different name than the one you declared them with. Just do a view
source in your browser to see it for yourself.
NOTE that this is a slightly different code example than your code of a contentpage so be careful when you take over the code!
ahmed_fci2006
i want to use upload file as standard not input
This is very easy:
Just remove the input control and place a FileUpload-control on the page. Set it's visibility style to hidden.
Then just replace all occurances of File1 on the page with the id of the FileUpload control
I checked this and the functionality remains the same.
If you have questions/remarks please do so!
Kind regards,
Wim
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
The code posted by Win should work... the really issue here is What will we do with the file (file path or file name)?
Post a file in a server is a little bit complicated, going on a step forward (after we get the file name in some way)... How do we post the file to the server? The HTTPPostedFile class has its "FileName" property as "Read Only", also the "FileName" property
of the UploadFile control... I spent a little time trying and finally I had to use the UploadFile as it. I improve a little the interface using this version of an UploadFile
http://en.fileuploadajax.subgurim.net/ works fine, and so far it results stable.
I hope help somebody
Hi rdelgadoj,
The net is full with examples about how to post a local file to the webserver once you got the FileName:
If you have questions/remarks please do so!
Kind regards,
Wim
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
1- when I make fileupload visibility hidden "visible=false" the fileupload doesn't work.
When you set the property visible of the control to false, this is a parameter that will be handled on the server-side when the page gets rendered.
What I'm trying to say is: When you set that property to false, when the page renders, it just doesn't create the button!!!
Look at the source (through the browser) of the page when the page is loaded and you have set the visible-property of the control to false. The control just isn't there.
SOLUTION:
Use a css style to hide the button!
Or you use a css file and link it to the control or you can set the style property of the control.
ahmed_fci2006
2-when make it visible it opens fileupload path but "image path doesn't appear in file upload txt".
Not sure what is causing this ...
Did you use my code as is?? Make sure all controls are runat="server".
If it is not working ... is there an error occuring? Maybe a javascript error (--> yellow triangle in the bottom-left of browser)
Kind regards,
Wim
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
I'm user your trick in a UC and publish it in website, now when I press submit button , page don't submit and focus move to first filled fileuploadif I remove"visibility:hidden" filupload! Other wise (I set visibility to hidden) submit button don't work while all of hidden fileupload become empty.
deblendewim
Contributor
5590 Points
951 Posts
Re: How to change Text in FileUpload control
Sep 19, 2007 12:35 PM|LINK
Hi ahmed,
The code given is actually an aspx page. Only the content inside the <html></html> is given.
Can you be a bit more specific about what you want to achieve? Do you want your customized fileupload on the master, child?
How do you want to customize it etc.
Did you try to add the above code to your application?
Do you get errors, what goes wrong?
Kind regards,
Wim
ahmed_fci200...
Member
12 Points
12 Posts
Re: How to change Text in FileUpload control
Sep 20, 2007 11:51 AM|LINK
thx Wim for replaying me.
look Wim that is the code I write it and it doesn't work see it and replay me ok thx .
<%
@ Page Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" CodeFile="final.aspx.cs" Inherits="test_Default" Title="Untitled Page" %><
asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <script language="JavaScript"><!--
function fireFileClick(){
var objfile = document.getElementById('File1');objfile.click();
var objTextBox = document.getElementById('Text1');objTextBox.value = objfile.value;
}
function setHiddenValue(){
document.getElementById("Hidden1").value = document.getElementById("File1").value;}
// -->
</script> <input id="Hidden1" type="hidden" /> <input runat="server" onchange="setHiddenValue()" id="File1" type="file" style=" visibility:hidden;" /> <br /> <br /> <asp:Button ID="Button1" OnClientClick="fireFileClick()" runat="server" Text="ASPNET Button" /> <input id="Text1" type="text" /> <br /> <br /> <input id="Button2" type="button" onclick="fireFileClick()" value="HTML Button" /> <br /> <br /></
asp:Content>ahmed_fci200...
Member
12 Points
12 Posts
Re: How to change Text in FileUpload control
Sep 20, 2007 11:51 AM|LINK
thx Wim for replaying me.
look Wim that is the code I write it and it doesn't work see it and replay me ok thx .
<%
@ Page Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" CodeFile="final.aspx.cs" Inherits="test_Default" Title="Untitled Page" %><
asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <script language="JavaScript"><!--
function fireFileClick(){
var objfile = document.getElementById('File1');objfile.click();
var objTextBox = document.getElementById('Text1');objTextBox.value = objfile.value;
}
function setHiddenValue(){
document.getElementById("Hidden1").value = document.getElementById("File1").value;}
// -->
</script> <input id="Hidden1" type="hidden" /> <input runat="server" onchange="setHiddenValue()" id="File1" type="file" style=" visibility:hidden;" /> <br /> <br /> <asp:Button ID="Button1" OnClientClick="fireFileClick()" runat="server" Text="ASPNET Button" /> <input id="Text1" type="text" /> <br /> <br /> <input id="Button2" type="button" onclick="fireFileClick()" value="HTML Button" /> <br /> <br /></
asp:Content>ahmed_fci200...
Member
12 Points
12 Posts
Re: How to change Text in FileUpload control
Sep 20, 2007 12:01 PM|LINK
sorry for repeating it is my mistake sorry but i want to use upload file as standard not input becouse this control in about 40 page and i can't change the code from start again so try to help me [:)]
rdelgadoj
Member
9 Points
5 Posts
Re: How to change Text in FileUpload control
Sep 20, 2007 12:36 PM|LINK
Just for notice!
The code posted by Win should work... the really issue here is What will we do with the file (file path or file name)?
Post a file in a server is a little bit complicated, going on a step forward (after we get the file name in some way)... How do we post the file to the server? The HTTPPostedFile class has its "FileName" property as "Read Only", also the "FileName" property of the UploadFile control... I spent a little time trying and finally I had to use the UploadFile as it. I improve a little the interface using this version of an UploadFile http://en.fileuploadajax.subgurim.net/ works fine, and so far it results stable.
I hope help somebody
deblendewim
Contributor
5590 Points
951 Posts
Re: How to change Text in FileUpload control
Sep 21, 2007 12:55 PM|LINK
Hi ahmed,
You're right about the code not working ....
The cause of this is the document.getElementById. On a masterPage, when the page gets rendered to be displayed (meaning the master and content-page will merge) the ID's of the controls get a different name than the one you declared them with. Just do a view source in your browser to see it for yourself.
So a working solution is this ....
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" title="Untitled Page" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <script type="text/javascript"> <!-- function fireFileClick() { var objfile = document.getElementById("<%= File1.ClientID %>"); objfile.click(); var objTextBox = document.getElementById("<%= Text1.ClientID %>"); objTextBox.value = objfile.value; } function setHiddenValue() { document.getElementById("<%= Hidden1.ClientID %>").value = document.getElementById("<%= File1.ClientID %>").value; } // --> </script> <input id="Hidden1" type="hidden" runat="server" /> <input runat="server" onchange="setHiddenValue()" id="File1" type="file" style=" visibility:hidden;" /> <br /> <br /> <asp:Button ID="Button1" OnClientClick="fireFileClick()" runat="server" Text="ASPNET Button" /> <input id="Text1" type="text" runat="server" /> <br /> <br /> <input id="Button2" type="button" onclick="fireFileClick()" value="HTML Button" /> <br /> <br /> </asp:Content>NOTE that this is a slightly different code example than your code of a contentpage so be careful when you take over the code!
This is very easy:
Just remove the input control and place a FileUpload-control on the page. Set it's visibility style to hidden.
Then just replace all occurances of File1 on the page with the id of the FileUpload control
I checked this and the functionality remains the same.
If you have questions/remarks please do so!
Kind regards,
Wim
deblendewim
Contributor
5590 Points
951 Posts
Re: How to change Text in FileUpload control
Sep 21, 2007 01:22 PM|LINK
Hi rdelgadoj,
The net is full with examples about how to post a local file to the webserver once you got the FileName:
Here are some links:
http://aspalliance.com/150_How_to_Upload_files_in_ASP_NET
http://www.codeproject.com/aspnet/FileHandlerPackage.asp
http://www.15seconds.com/issue/010504.htm
If you have questions/remarks please do so!
Kind regards,
Wim
ahmed_fci200...
Member
12 Points
12 Posts
Re: How to change Text in FileUpload control
Sep 23, 2007 08:31 AM|LINK
Wim thx the code working but [:(] there is two problem with me
1- when I make fileupload visibility hidden "visible=false" the fileupload doesn't work.
2-when make it visible it opens fileupload path but "image path doesn't appear in file upload txt".
[:(] I really don't know why it doesn't work with
deblendewim
Contributor
5590 Points
951 Posts
Re: How to change Text in FileUpload control
Sep 23, 2007 01:37 PM|LINK
Hi ahmed,
I'm glad the code is working now ....
To answer your questions:
When you set the property visible of the control to false, this is a parameter that will be handled on the server-side when the page gets rendered.
What I'm trying to say is: When you set that property to false, when the page renders, it just doesn't create the button!!!
Look at the source (through the browser) of the page when the page is loaded and you have set the visible-property of the control to false. The control just isn't there.
SOLUTION:
Use a css style to hide the button!
Or you use a css file and link it to the control or you can set the style property of the control.
Not sure what is causing this ...
Did you use my code as is?? Make sure all controls are runat="server".
If it is not working ... is there an error occuring? Maybe a javascript error (--> yellow triangle in the bottom-left of browser)
Kind regards,
Wim
mfarshadmehr
Member
279 Points
151 Posts
Re: How to change Text in FileUpload control
Nov 17, 2007 10:26 AM|LINK
Hi,
I'm user your trick in a UC and publish it in website, now when I press submit button , page don't submit and focus move to first filled fileupload if I remove "visibility:hidden" filupload! Other wise (I set visibility to hidden) submit button don't work while all of hidden fileupload become empty.
Any one can help me?
Thanks for your reply!