Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I am having a hyperlink called Attach file .If i click on that hyperlink "Attach File" than the browse window should have to appear .Can any one help me to do this
Posted

Add this javascript function.
function clickfp() {
    var objFp = document.getElementById('<%= fpUpload.ClientID %>');
    objFp.click();
}

Call javascript function on hyperlink onclick.
XML
<input type="file" id="fpUpload" runat="server" name="filediag" style="display:none" />
   <asp:HyperLink ID="hlClick" runat="server" Text="Upload" onclick="clickfp();"></asp:HyperLink>
 
Share this answer
 
Comments
Imran D 11-Jul-12 4:34am    
Thank you pradiprenushe . Its working , but the file upload control is enabled, what should i do to disable the file upload control?
pradiprenushe 11-Jul-12 4:41am    
enabled means is it visible?
Imran D 11-Jul-12 4:47am    
Ya file upload control is visible, it should be in disable position.only If i click on that hyperlink "Attach File" than the browse window should have to appear.By clicking Both hyperlink "Attach File" & file upload the browse window is appearing.Its like Gmail.When you click on attach file in Gmail the browse window will appears.Like that i want.I dont want file upload control
pradiprenushe 11-Jul-12 5:20am    
can u paste your code? Actually file upload it should not display.
Imran D 11-Jul-12 5:31am    
<pre lang="HTML"><head runat="server">
<script type="text/javascript" language="javascript">
function clickfp() {
var objFp = document.getElementById('objFileUpload');
objFp.click();
}
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="#" onclick="clickfp();">Add file
<br />

<asp:FileUpload ID="objFileUpload" runat="server" />
<br />
<br />
<asp:Button ID="btnUpload" runat="server" onclick="btnUpload_Click"
Text="Upload" />
<br />

</div>
</form>
</body></pre>
Use the Window[^] object in JavaScript, in an onclick event of the link, with href="#". Or simply use the href as normally, and add a target="_blank", but you will have no control over the window.
By the way "should have to appear" is unclear since it has to be visible to click on a link...
 
Share this answer
 
Comments
Imran D 11-Jul-12 3:37am    
But how browse window appears? i dint get u
Zoltán Zörgő 11-Jul-12 3:41am    
Sorry, I have misunderstood you! I meant "web browser windows", but you want the "file browser dialog" to appear. Ok, than see pradiprenushe's answer.
Imran D 11-Jul-12 4:31am    
Thank U

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