0
votes

In my ASP.NET website, I have to add browse file from file upload window, but for some design sake Textbox and Button control has used in the page.

<asp:Button ID="Button1" runat="server" onclick="Button1_Click1" 
            Text="Button" />
     <input type="file"  runat="server" id="myfile"/>

Display of this file upload control is none..

I used Jquery plugins in the header tag as below,

<head>
--
     <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript">
            </script><script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
            <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    </head>

And in my server side code , in the button click event I have code as below,

 protected void Button1_Click1(object sender, EventArgs e)
    {
         StringBuilder strScript = new StringBuilder();
       strScript.Append("$(document).ready(function(){");
         strScript.Append("('myfile').click();");
         strScript.Append("});");
       Page.ClientScript.RegisterStartupScript(this.GetType(), "Script",
         strScript.ToString(), true);
    }

The above code is not opening the fileupload window. Please give some suggessions.

2

2 Answers

0
votes

You haven't included a # in your jquery selector e.g.

 strScript.Append("('#myfile').click();");
0
votes

I don't think its a good idea to call server for opening fileupload dialog.

You can achieve it via javascript or jQuery.

You can add onclientClick event to the button and execute the javascript which might require..

There is similar kind of question already asked in SO.. Check it open file upload dialog on click