Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi i am using this code for Browse image on single button click..

this is java script code....
C#
<script type="text/javascript" language="javascript">

    function getFile() {

        document.getElementById("file1").click();
        var file = "";

        document.getElementById("TextBox1").value = "";
        document.getElementById("TextBox1").value = document.getElementById("file1").value;
      //  document.getElementById("Image1").ImageUrl = document.getElementById("FileUpload1").value;
    }

</script>



this is control
XML
<input id="file1" style="left: 106px; width: 1px; position: absolute; top: 184px; visibility : hidden;" type="file" />
       <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


and this code i am written on form_load()...
ImageButton1.Attributes.Add("OnClick", "return getFile();");

it work properly in internet explorer..

but it not return any thing on any other browser...
please solve my problem
Posted
Updated 16-Mar-11 7:23am
v4
Comments
Albin Abel 16-Mar-11 12:39pm    
document.getElementById("file1").value; this is not supported in many browsers
Albin Abel 16-Mar-11 12:44pm    
I wonder how it works in IE, because you are not using ClientID for the text box in javascript. Even if it works now it won't work later if you add more hierarchy. If you want to access the ID as such then set the ClientIDMode to static for the textbox
Sandeep Mewara 16-Mar-11 14:08pm    
For HTML controls, ID directly works and no issues.

It's the server controls that needs clientID specially when you are using nested pages.
Ali Al Omairi(Abu AlHassan) 17-Mar-11 19:00pm    
you mean document.getElementById('<%= TextBox1.ClientID %>') ?!
Albin Abel 18-Mar-11 0:16am    
Yo are right, but he is using a web server control for text box <asp:TextBox ID="TextBox1" runat="server">

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