I have an asp.net page with a FileUpload control so that the user can browse to select a file. I wanted to assign a default value so the user doesn't need to browse unless they're doing something out of the norm, but the File properties are read-only.
So I set the Visible property of the FileUpload control to false and put in a textbox and button. In that textbox I put the default path I want. When the user clicks the button I want it to open the Browse window that clicking the FileUpload control would. I have this:
<head>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"/>
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE"/>
<meta content="JavaScript" name="vs_defaultClientScript"/>
<meta content="http://schemas.microsoft.com/intellisense/ie5"name="vs_targetSchema"/>
<script src="common.js" type="text/javascript"></script>
<script type="text/javascript">
function fileBrowse()
{
document.getElementById('FileBrowse').click();
}
</script>
</head>
And then in the code I have this:
Protected Overrides Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyBase.Page_Load(sender, e)
Me.btnINI.Attributes.Add("onclick", "javascript:fileBrowse();")
End Sub
FileBrowse is the name of the FileUpload control on the page. btnINI is the name of the button that I want to launch the browse.
When I click the button nothing happens - no errors, nothing is launched. Any help would be much appreciated!