CALL FILE UPLOADER FROM A BUTTON CLICK
method 1
we cannot change the text of file uploader(ajax asynch fileuploader) ,but we can call it from button click.
1)set file uploader width and height=0;
<asp:AsyncFileUpload ID="AsyncFileUpload1" Width="0px" Height="0px" runat="server" OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />
<asp:AsyncFileUpload ID="AsyncFileUpload1" Width="0px" Height="0px" runat="server" OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />
2)call the file uploader from a button
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" OnClientClick="document.getElementById('AsyncFileUpload1_ctl02').click(); return false" Text="Upload Now..." />
3) get file name incode behind
3) get file name incode behind
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
string file = System.IO.Path.GetFileName(AsyncFileUpload1.PostedFile.FileName);
}
method =2
if you are using html file uploder you can use this method
1)test is a javascript function which is onlyused for perform post back operation ,you can use any other method to perform postback.
<input type="file" class="_n _5f0v" title="Choose a file to upload" onchange="test();" accept=".txt" name="file" id="FileUpload11" runat="server" />
call html fileupload click event from asp button(or html)
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" OnClientClick="document.getElementById('FileUpload11').click(); return false" />
<script type="text/javascript">
function test() {
var x = document.getElementById("FileUpload11").value;
document.getElementById("<%= Button3.ClientID %>").click();
}
</script>
here button3 is used to perform post back operation you will get the value in code behind by using following code
int contentLength = FileUpload11.PostedFile.ContentLength;//You may need it for validation
string contentType = FileUpload11.PostedFile.ContentType;//You may need it for validation
string fileName = FileUpload11.PostedFile.FileName;
{
string file = System.IO.Path.GetFileName(AsyncFileUpload1.PostedFile.FileName);
}
method =2
if you are using html file uploder you can use this method
1)test is a javascript function which is onlyused for perform post back operation ,you can use any other method to perform postback.
<input type="file" class="_n _5f0v" title="Choose a file to upload" onchange="test();" accept=".txt" name="file" id="FileUpload11" runat="server" />
call html fileupload click event from asp button(or html)
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" OnClientClick="document.getElementById('FileUpload11').click(); return false" />
<script type="text/javascript">
function test() {
var x = document.getElementById("FileUpload11").value;
document.getElementById("<%= Button3.ClientID %>").click();
}
</script>
here button3 is used to perform post back operation you will get the value in code behind by using following code
int contentLength = FileUpload11.PostedFile.ContentLength;//You may need it for validation
string contentType = FileUpload11.PostedFile.ContentType;//You may need it for validation
string fileName = FileUpload11.PostedFile.FileName;
key words-how to call asp file uploader from a button click,file uploader click event,how to call file uploader from a button ,call file uploader,call ajax file uploader from a button click,change the file uploader text name,how to change file uploader text-browse fromcustome format,asp file uploader properties,asp file uploader clikc event call code behind,
0Awesome Comments!