Click here to Skip to main content
15,745,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have this ASPX page..

<html xmlns="">
<head runat="server">
    <style type="text/css">
            background-image: url('../Images/Camera.png');
            width: 120px;
            height: 90px;
    <script type="text/javascript">
        function SelectFile() {
            document.getElementById('<%= imageUpload.ClientID %>').click();
        function SubmitForm() {
            __doPostBack('btnSubmit', '');
        function __doPostBack(eventtarget, eventargument) {
            document.form1.__EVENTTARGET.value = eventtarget;
            document.form1.__EVENTARGUMENT.value = eventargument;
    <form id="form1" runat="server">    
        <input type="hidden" id="__EVENTTARGET" value="" />
        <input type="hidden" id="__EVENTARGUMENT" value="" />
        <input type="button" runat="server" id="btnFileSelect" value="" class="FileSelect" onclick="SelectFile();"/> 
        <asp:FileUpload ID="imageUpload" runat="server" style="display:none;" onchange="SubmitForm()" />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" style="display:none;" />    

and in my code behind page like this..

protected void Page_Load(object sender, EventArgs e)
       protected void btnSubmit_Click(object sender, EventArgs e)


when __doPostBack is Called at that time the line

will give me this error

"htmlfile: Access is denied"

how to resolve this...
Updated 13-Oct-11 10:50am

1 solution

You cannot call the click() method from javascript of a FileUpload control. It also isn't possible to set or clear the value using javascript. It is considered a security violation. You could however read the value to check the file extension for example.

Some extra info:[^][^]

Good luck!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900