This is a migrated thread and some comments may be shown as answers.

Run Code Behind From Javascript

3 Answers 808 Views
Button
This is a migrated thread and some comments may be shown as answers.
Tracy
Top achievements
Rank 1
Tracy asked on 14 Jan 2018, 08:45 PM

Hi I have a button that I want to disable on click and then run the code behind on the button.  The following is the code I have but the code behind click event never fires.  The button gets disabled but OnClick event never fires.

Thank you for you assistance.

Tracy

 

<script  type="text/javascript" >
     function AddJob(sender, args) {
         sender.set_enabled(false);
         sender.click();
     }
  
 </script><body>
  <form id="form1" runat="server">
      <act:ToolkitScriptManager ID="tsmManager"  runat="server"  EnablePartialRendering="true" AsyncPostBackTimeOut="600" ScriptMode="Release" EnablePageMethods="true"/>
  <div>
      <telerik:RadButton ID="rbtAddJob"           runat="server" AutoPostBack="true" ButtonType="StandardButton"      Text="Add This Job To My Jobs"      OnClientClicked ="AddJob"       OnClick="rbtAddJob_Click" Width="150px"/>
  </div>
Protected Sub rbtAddJob_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbtAddJob.Click
       MsgBox("test")
   End Sub

 

 I also tried this code

<script  type="text/javascript" >
     function AddJob(sender, args) {
         var btn = $find("rbtAddJob");
         btn.set_enabled(false);
         btn.click();
      }
   
  </script>

3 Answers, 1 is accepted

Sort by
0
Accepted
Vessy
Telerik team
answered on 15 Jan 2018, 09:19 AM
Hi Tracy,

The purpose of the set_enable(false) logic of Button is not only to visually disable the element of the control, but to disable its client-side funtionality as well, thus it is expected for the click method of a disabled button fo not funtion. 

If you want to have button that is disabled after the first click and execute a server side logic in the same time, I woudl advise that you consider setting the button's SingleClick property to true:
<script type="text/javascript">
    function AddJob(sender, args) {
        alert("client click");
    }
</script>
<telerik:RadButton ID="rbtAddJob" runat="server" AutoPostBack="true" ButtonType="StandardButton" Text="Add This Job To My Jobs" OnClientClicked="AddJob" OnClick="rbtAddJob_Click" Width="150px" SingleClick="true" />
Protected Sub rbtAddJob_Click(sender As Object, e As EventArgs) Handles rbtAddJob.Click
    MsgBox("test server-click")
End Sub


Regards,
Vessy
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Tracy
Top achievements
Rank 1
answered on 15 Jan 2018, 03:51 PM
Thank you Vessy that worked.
0
Vessy
Telerik team
answered on 15 Jan 2018, 03:56 PM
Hi,

You are welcome. Tracy. Let us know whenever any further issue with our controls occurs.

Regards,
Vessy
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Button
Asked by
Tracy
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Tracy
Top achievements
Rank 1
Share this question
or