Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

disable button

Posted on 2011-09-28
29
Medium Priority
?
766 Views
Last Modified: 2012-05-12
I have a one RadUpload and one RadButton - called Upload... I want to hide RadButton unless user Selected a file from RadUpload.. how can I do that?
0
Comment
Question by:1jaws
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 16
  • 8
  • 3
  • +1
29 Comments
 
LVL 59

Expert Comment

by:HainKurt
ID: 36718663
when file is uploaded set RadButton.visible = false
0
 

Author Comment

by:1jaws
ID: 36718680
thank you for replying... I am disabling the RadButton unless user clicked RadUpload's Select button and selected a file to upload.. basically, I need to check if there is a file shows on that textbox's of the RadUpload
0
 
LVL 59

Accepted Solution

by:
HainKurt earned 668 total points
ID: 36718758
here
<input type="file" name=btnFile id=btnFile size="chars" onChange="chk()">
<button id=btnUpload disabled>upload</button>
<script>
function chk(){
  btnUpload.disabled = (btnFile.value =="");
}
</script>

Open in new window

0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Comment

by:1jaws
ID: 36718799
ok but this is not RadUpload, it is regular input type .. file.. cant I do that with RadUpload?
0
 
LVL 12

Assisted Solution

by:jagssidurala
jagssidurala earned 668 total points
ID: 36718817
0
 

Author Comment

by:1jaws
ID: 36718947
used second link.. I get this error
Microsoft JScript runtime error: 'FileInputField.value' is null or not an object

function myOnClientFileSelected(radUpload, eventArgs)
{

        var selectedFileName = eventArgs.FileInputField.value.toLowerCase();  <---gives error when page loads because no file name  selected yet...
        if(selectedFileName != null)
        {
        btnUpload.disabled = "false";
        }
       
}
0
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36718998
Check for null value like below


function myOnClientFileSelected(radUpload, eventArgs)
{
if(eventArgs != null && eventArgs.FileInputField != null)
{
        var selectedFileName = eventArgs.FileInputField.value.toLowerCase();  <---gives error when page loads because no file name  selected yet...
        if(selectedFileName != null)
        {
        btnUpload.disabled = "false";
        }
}

       
}
0
 

Author Comment

by:1jaws
ID: 36719094
I did and nothing happening.. my button still disabled... something not right.. here my code... I made btnUpload enabled = false at the beginning so made that enabled true...below..

function myOnClientFileSelected(RadUpload, eventArgs) {

    alert("hi");
      if(eventArgs != null && eventArgs.FileInputField != null)
        {
            var selectedFileName = eventArgs.FileInputField.value.toLowerCase();
            if(selectedFileName != null)
            {
            btnUpload.enabled = "true";
            }
        }      
}
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 36719176
Instead of
".enabled=false"
use
".disabled=true"

and when condition is satisfied change it to
".disabled=false"
0
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36719186
instead of below code

btnUpload.enabled = "true";

write

$('#btnUpload').attr("disabled", false);

or

$('#btnUpload").removeAttribute("disables");

you need to call jquery latest javascrit file in head section

0
 
LVL 18

Assisted Solution

by:nap0leon
nap0leon earned 664 total points
ID: 36719209
minor typo in jagssidurala's last post:

this:
$('#btnUpload").removeAttribute("disables");

should be:
$('#btnUpload").removeAttribute("disabled");

"disables" instead of "disabled"

The main ideas are:
1- you disable something by adding the "disabled" attribute, not by toggling an "enabled" attribute.
2- it is better to turn off "disabled" by removing it, rather than setting it to "false" (not sure why, but this question shows up periodically)
0
 

Author Comment

by:1jaws
ID: 36719237
I used this  $('#btnUpload").removeAttribute("disabled");  says Unterminated string constraint
0
 

Author Comment

by:1jaws
ID: 36719253
would this be easier if we use visible ... true/false....
0
 

Author Comment

by:1jaws
ID: 36719272
how will I get the latest javascript thing..? no idea...
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 36719308
bad combination of single quotes and double quotes.
try this:
$('#btnUpload').removeAttribute('disabled');
0
 

Author Comment

by:1jaws
ID: 36719312
tried this says object not supported..$('#btnUpload').attr("disabled", false);
0
 

Author Comment

by:1jaws
ID: 36719323
Microsoft JScript runtime error: Object doesn't support this property or method after your last comment..
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 36719329
If you are not using jQuery, the line above would be (I think, I'm not actually testing this as I type):

document.getElementById("btnUpload").removeAttribute("disabled");
0
 

Author Comment

by:1jaws
ID: 36719341
Microsoft JScript runtime error: 'document.getElementById(...)' is null or not an object
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 36719351
Also could try this:
btnUpload.removeAttribute('disabled');

or this:
var thisButton = document.getElementById("btnUpload");
thisButton.removeAttribute('disabled');

(Sorry to be spammy with answers... it depends on what you have declared where and whether those things are in scope or not, etc.)
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 36719361
Perhaps the issue is your button is id="RadButton" and not "btnUpload" as the previous answers all suggest.
0
 

Author Comment

by:1jaws
ID: 36719396
no it is btnUpload and I keep getting null value as of the the button, tried your last ex. I get object null error
<telerik:RadButton ID="btnUpload" runat="server" Text="Upload"
        onclick="btnUpload_Click"  Enabled="false">
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 36719430
only reason to get that error is that the Id does not match.
When you view source (or inspect w/ Firebug, etc.), what is the button's Id?
0
 

Author Comment

by:1jaws
ID: 36719450
<table>
  <tr>
    <td>
         <telerik:RadUpload ID="RadUpload1" runat="server" Width="245px" InitialFileInputsCount="1"
        MaxFileInputsCount="1" AllowedFileExtensions=".jpg, .tif"  OnClientFileSelected="myOnClientFileSelected">
    </telerik:RadUpload>
     
    </td>
    <td valign="top">
       <telerik:RadButton ID="btnUpload" runat="server" Text="Upload"
        onclick="btnUpload_Click"  Enabled="false">
    </telerik:RadButton>
    </td>
  </tr>
</table>

here my full code for this...so it is called btnUpload I have no idea why it is null
0
 

Author Comment

by:1jaws
ID: 36719488
this is in master page.. maybe that's why?
0
 

Author Comment

by:1jaws
ID: 36719722
found this answer but dont actually know how to implement that because when I put this function on the master page, it complains because I dont have button like that...
http://stackoverflow.com/questions/5886617/disable-button-on-masterpage-net-4-0-c
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 36719948
What does "View Source" show for the element you are trying to enable?

JavaScript runs on the client, not the server.
To debug the JavaScript error, it is best to look at the rendered code - what you see when you "View Source".  Once you see what the error is, you can then either adjust your server side code to make it match what your JS is trying to do or change your JS to match what your server-side code is creating.
0
 

Author Comment

by:1jaws
ID: 36720038
I am attaching view source.. I have even tried this without master page still getting null value for my btnUpload.... arrgghhh.. drives me crazy.
test.txt
0
 

Author Closing Comment

by:1jaws
ID: 36731296
figured it out different by just adding <div> and control that way.. Thank you all for trying to help!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question