This is a migrated thread and some comments may be shown as answers.
Set Enabled / Disabled RadButton from client side
10 Answers 1112 Views
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 10 Jan 2011, 10:41 AM
Hi Telerik-Team,

I make my first experience with RadButton.
Simple Question - hao can I  set enable property from client side? 
javascript  not working and RadButton still remain disabled:

function

 

EnableDisable() {
    button2 = document.getElementById(
"RadButton2_input");
    button2.disabled =
false;
}

 

Thanks in advance!

10 Answers, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 10 Jan 2011, 11:10 AM
Hello Michael,

The RadButton control creates a client-side object, as all of our Ajax enabled RadControls do. To get a reference to this object you should use the $find(controlId) method. After you have a reference to the control, you could use its client-side methods, and more specifically you could enable/disable the button itself using the set_enabled(toEnable) method. Your code will look like the following:

function EnableDisable() {
    var button2 = $find("RadButton2");
    button2.set_enabled(false);
}

Regards,
Pero
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Michael
Top achievements
Rank 1
answered on 10 Jan 2011, 11:20 AM
Hello Pero,

it works fine!
Thank you very much for your quick replies!

Best regards,
Michael
0
JJ
Top achievements
Rank 1
answered on 18 Jan 2012, 04:22 PM

My button is nested inside radgrid.

when form load, use

var button2 = $find("RadButton2");

will not find the button and will get error

I used view source to get the button id - ctl00_MainContent_ucDataDropOffUCPhase1_RadPanelBar1_i0_rggrid

var btn = document.getElementById("ctl00_MainContent_ucDataDropOffUCPhase1_RadPanelBar1_i0_rggrid");
btn.set_enabled(true);

it gives me error object does not surrport this propery or method.

What control I need to use in order to use btn.set_enabled?

Thanks
0
Slav
Telerik team
answered on 20 Jan 2012, 01:36 PM
Hello,

To get the reference to the RadButton's client-side object correctly, you should use the $find(controlId) method, as explained by Pero:
var btn = $find("ctl00_MainContent_ucDataDropOffUCPhase1_RadPanelBar1_i0_rggrid");
btn.set_enabled(true);

Another option for referencing the RadButtons in a RadGrid is to use their client-side event OnClientLoad in order to retrieve the client-side object of every button and to populate a global array of buttons.

RadButton inside the RadGrid
<telerik:RadButton ID="checkAssigned" runat="server" OnClientLoad="ButtonLoad">
</telerik:RadButton>

Global array declaration and OnClientLoad event handler:
<script type="text/javascript">
    var buttons = [];
    function ButtonLoad(sender, args)
    {
        Array.add(buttons, sender);
    }
</script>

Regards,
Slav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Michael
Top achievements
Rank 1
answered on 16 Jul 2012, 12:08 PM
That's not valid. 

My button is declared as:

<telerik:RadButton runat="server" ID="rbtnSave" Text=" Save " ButtonType="StandardButton" CommandName="Save" CommandArgument="SaveChanges" Enabled="false" />

In order to change the enabled property I had to use:

$('#<%=rbtnSave.ClientID%>')[0].control.set_enabled(true);

The important different being the added "[0].control" bit. I use <%=rbtnSave.ClientID%> so my JS will work with ASP.Net dynamic IDs correctly.
0
Doug
Top achievements
Rank 1
answered on 18 Jul 2012, 01:08 AM
I recommend trying $find("<%= radbuttonID.ClientID %>");
for example, my RadButton is implemented in part as:

<telerik:RadButton ID="saveAs" AutoPostBack="false" runat="server" OnClientClicked="SaveResults" ...
In my script I have a function that needs to enable/disable the button, so it uses this line of code:
var saveButton = $find("<%= saveAs.ClientID %>");
and then:
saveButton.set_enabled(true); // or false

Works for me

 

0
JJ
Top achievements
Rank 1
answered on 04 Aug 2014, 01:58 PM
Hi

When the user click on the save button of the RadGrid and it is not valid it does nothing and when the RadGrid is valid it does save. That all works fine...

I want to alert a message on client side when RadGrid is not valid. How can I check in java-script function when the RadGrid is valid or not for save?


<telerik:RadGrid
...
 
<CommandItemTemplate>
                            <asp:Button runat="server" ID="UpdateAll" Text="Save" CommandName="UpdateAll" OnClientClick="return UserSaveConfirmation();"  />
                            <asp:Button runat="server" ID="CancelAll" Text="Cancel" CommandName="CancelAll"  OnClientClick="if ( ! UserCancelConfirmation()) return false;" />
 
 
   </CommandItemTemplate>
 
...
 
 
  </telerik:RadGrid>
 
 
 <telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
 
         <script type="text/javascript">
 
                   function UserSaveConfirmation() {
 
                                var radGrid = $get("rdRoutineAttributeValuesDetails");
 
                                 ?? if RadGrid.IsValid() { alert('Cannot save, grid values format is not valid. Please correct and try again.') return false;}
 
}













0
Danail Vasilev
Telerik team
answered on 07 Aug 2014, 06:18 AM
Hi JJ,

You can try to pass the id of the cell that you want to validate to the UserSaveConfirmation function in the ItemDataBound event, following the approach from this forum post.

Regards,
Danail Vasilev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Bhavik
Top achievements
Rank 2
answered on 03 Nov 2014, 09:46 AM
Hi,

Earlier i was facing same issue, here there is a difference with id what we used to find control.

in my case, i am using AutoCompletebox in repeater control, html is rendered with ID = "CBR1_rptCallBackReason_ctl10_ddlRequestLine_Input", but to make it enable/disable following code worked

var cmb =
$find("CBR1_rptCallBackReason_ctl10_ddlRequestLine");
cmb.set_enabled(true);

i need to remove _input from id.

0
Peter
Top achievements
Rank 1
answered on 23 Apr 2015, 03:16 AM

This worked for me (note the SetTimeout to ensure the server event still fires):

 

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function SendClicked(sender, args) {
                var btnSendToVrp = $find("<%=btnSend.ClientID %>");
 
                setTimeout(function(){
                    btnSendToVrp.set_enabled(false);
                    btnSendToVrp.set_text('Please Wait...'); },
                    200);
            }
        </script>
    </telerik:RadCodeBlock>

 

<telerik:RadButton runat="server" ID="btnSend" Text="Send" OnClick="btnSend_Click" OnClientClicked="SendClicked" />

Asked by
Michael
Top achievements
Rank 1
Answers by
Pero
Telerik team
Michael
Top achievements
Rank 1
JJ
Top achievements
Rank 1
Slav
Telerik team
Michael
Top achievements
Rank 1
Doug
Top achievements
Rank 1
JJ
Top achievements
Rank 1
Danail Vasilev
Telerik team
Bhavik
Top achievements
Rank 2
Peter
Top achievements
Rank 1
Share this question
or