In my web site I have the following asp.net code:
<div id="FileBrowserDiv" runat="server" class="FileBrowserDiv" >
<asp:Button ID="UpLoadFile" runat="server" Text="File Selection" CssClass="FileSelection" OnClick="fireFileClick()" />
<asp:FileUpload ID="UpLoadButton" runat="server" cssclass="FakeButton" />
<script type="text/javascript">
function fireFileClick() {
var objfile = document.getElementById("<%= UpLoadButton.ClientID %>");
objfile.click();
var objTextBox = document.getElementById("<%= UpLoadButton.ClientID %>");
objTextBox.value = objfile.value;
</script>
<div id ="filelabeldiv" runat="server" class="FileLabelDiv">
<asp:Label ID="FileLabel" runat="server" CssClass="FileLabel" />
</div>
<asp:Button ID="FileSave" runat="server" Text="Save File" CssClass="FileSave" />
</div>
And in my code behind I have a function:
Public Function UpLoadBtn_change()
If IsPostBack Then
If UpLoadButton.HasFile Then
....Some code manipulating the Uploaded file....
End If
End If
End Function
What I'm trying to do here is:
By clicking the
UpLoadFile
Button I want to trigger the
asp:FileUpload
Button.
For this I'm running the
fireFileClick()
in Java script.
In `ie explorer` this situation it running well.
But in the other browsers its not work, when I'm trying to run the code behind function.
It is obviously that something is wrong on this code, but I can't figured where that mistake is placed.
And the reason for that is because I'm not a programmer in Java, in fact I don't have the special knowledge that I need.
Is there some one to assist me on this issue?
What I have tried:
What I discover until now is that:
When I push the first button
<asp:Button ID="UpLoadFile" runat="server" Text="File Selection" CssClass="FileSelection" OnClick="fireFileClick()" />
It triggers the script
var objfile = document.getElementById("<%= UpLoadButton.ClientID %>");
objfile.click();
Which click the next (hidden) button. That action gives me the opportunity to select the proper file to upload.
That file assign (with the help of the second line of the script)
var objTextBox = document.getElementById("<%= UpLoadButton.ClientID %>");
objTextBox.value = objfile.value;
Into the `fileupload` button (hidden). Thus this file it runs postback automatically and gives me the information I need.
IMPORTANT Be aware in the sequence of actions it is very
important.
That happens ONLY in the `ie explorer`.
In the other browsers the post back action triggers before the `fileupload` button takes its value thus returns me the result of "No file selected".
And there is my problem.
What could be the solution on this?