Click here to Skip to main content
16,020,990 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have one control fileupload
and button is "upload"


intially button should be not visible
after i select file after that upload button should enable how to do this
Posted
Comments
Member 10954869 14-Aug-14 7:09am    
my aspx code
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.fileupload
{
margin: auto;
line-height: 50;
position: static;
width: 100px;
height: 100px;
}
.button
{
margin-top: 10px;
}
.btn
{
display: block;
}
</style>
<script type="text/javascript">
function ValidateUpload()
{
$(document).ready(
function(){
$('#FileUpLoad1').change(
function(){
if ($(this).val()) {
$('#btnUpLoad').attr('disabled',false);
}
}
);
});
}


// function ValidateUpload() {
// var uploadcontrol = document.getElementById('<%=FileUpLoad1.ClientID%>').value;
// if (uploadcontrol.length > 0) {
// document.getElementById("<%=btnUpLoad.ClientID%>" ).style.display = 0
// alert("uyffsd");

// }
// else {
// return false;
// }
// return true;

}
function uploadAlert() {
var uploadcontrol = document.getElementById('<%=FileUpLoad1.ClientID%>').value;
//Regular Expression for fileupload control.
var Extension = uploadcontrol.substring(uploadcontrol.lastIndexOf('.') + 1).toLowerCase();
if (uploadcontrol.length > 0) {
//Checks with the control value.
if (Extension == "txt" || Extension == "csv") {
alert("File Uploaded Succesfully");
return true;
}
else {
//If the condition not satisfied shows error message.
alert("Only .txt, .csv files are allowed!");
return false;
}
}
else {
alert("Please Select File");
}
}
</script>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:UpdatePanel ID="upnlUserMgmt" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="btnUpLoad" />
</Triggers>
<contenttemplate>
<span>Create Bulk User</span>
<div align="center" class="fileupload">
<asp:FileUpload ID="FileUpLoad1" runat="server" ToolTip="Select a File" />
<div align="center">
<asp:Button ID="btnUpLoad" Text="UploadFile" OnClick="btnUpLoad_Click" OnClientClick="return uploadAlert();"
runat="server" Width="105px" CssClass="btn btn-info button" Visible="false"/>
<asp:RequiredFieldValidator ID="CustomValidator1" runat="server" ControlToValidate="FileUpLoad1"
ClientValidationFunction="return ValidateUpload();" ErrorMessage="Required File">

</div>
<asp:Label ID="lblresult" runat="server">
</div>


Member 10954869 14-Aug-14 7:10am    
try this and give solution for me after browse the file in fileupload control that Upload Button is not showing

JavaScript
$(document).ready(
    function(){
               $('#<%= FileUpload1.ClientID %>').change(function(){
               if($('#<%= FileUpload1.ClientID %>').val())
               {
                   $('#<%= Button1.ClientID %>).attr('disabled',false);
               }
               });
             });



hope this will help you
 
Share this answer
 
v3
First: Visible and Enable are two different properties. what are you looking for?
Second: Please search the web properly.. the links below are the similar questions you could easily get from google. Anyways take a look.

How to show an ASP Button only when FileUpload has file chosen

http://codeverge.com/asp.net.web-forms/how-to-enable-an-upload-button-after-fileup/415291

http://forums.asp.net/t/1976706.aspx?Enable+Disable+upload+button+depending+on+the+fileupload+textbox

You can achieve it from client side. Happy Coding! :)
 
Share this answer
 
assuming your button is
<input type="submit" value="Upload" disabled />

jquery:


C#
$(document).ready(
    function(){
        $('input:file').change(
            function(){
                if ($(this).val()) {
                    $('input:submit').attr('disabled',false);
                   
                }
            }
            );
    });
 
Share this answer
 
Comments
Member 10954869 14-Aug-14 5:38am    
not workng
NowYouSeeMe 14-Aug-14 5:51am    
http://jsfiddle.net/E42XA/
Member 10954869 14-Aug-14 6:22am    
working there but not working oin asp.net
NowYouSeeMe 14-Aug-14 6:41am    
replace
$('input:file') with $("#idofthefileinput") and $('input:submit') with $("#idofbutton").
Member 10954869 14-Aug-14 7:08am    
already done that modificatins not working

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