c# – calling right away a JavaScript from the backend


I want to call a JavaScript as soon as I am finished in backend in ASP.NET Web Form

 <table>
  <tr>
      <td>
           <asp:UpdatePanel ID="UpdatePanelSpin" runat="server"  UpdateMode="Conditional">
               <ContentTemplate>
                   <div id="spin">
                   </div>
               </ContentTemplate>
           </asp:UpdatePanel>
      </td>
      <td style="width:5px"></td>
       <td>
            <asp:Button ID="btnExecute" runat="server" ValidationGroup="btnExecute" OnClick="btnExecute_Click"
                Text="Execute" OnClientClick="spinStart();" />
       </td>
  </tr>

The JavaScript code

function spinStart() {
  console.log("Starting message");
  var target = document.getElementById('spin');
  var spinner = new Spinner(opts).spin(target);
}

function spinStop() {
   console.log("Done With sucess");
// does some stuff
}

at the backend

protected void btnExecute_Click(object sender, EventArgs e){
  // Do something
   CallMethod();
}

private void CallMethod()
{
  ScriptManager.RegisterStartupScript(this, this.GetType(), "spinStop", "spinStop();", true);
                       
}

spinStop is never called and I don’t have any message “Done With sucess” in the console but spinStart is called and the “Starting message” appears on the console.

I have replaced with

 ScriptManager.RegisterStartupScript(UpdatePanelSpin, UpdatePanelSpin.GetType(), "spinStop", "spinStop();", true);
 UpdatePanelSpin.Update()

but no success.
Any idea is appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *