Click here to Skip to main content
14,425,416 members
Rate this:
Please Sign up or sign in to vote.
I am trying to call a jquery function from inside a function and it is not working, although I am not getting any errors. I don't know what I am doing wrong as this is my first time trying to do this.

What I have tried:

Code behind:

Public Sub HideInsertNewRowButton()
ClientScript.RegisterClientScriptBlock(Me.GetType(), "Script", "DisableNewRow();", True)
End Sub

javascript from ASPX page

 function DisableNewRow() {

the element I want to hide from ASPX page:

<div class="collapse navbar-inverse navbar-collapse" collapse="navCollapsed">
       <ul class="nav navbar-nav">
         <li id="add" ng-hide="HideAppend">
         <a title="Add A New Row" href="#" ng-click="newRow($event)" ng-class="{'disabled' : ShowLoading}"></a>
Updated 29-Aug-19 12:04pm
F-ES Sitecore 29-Aug-19 10:07am
ids have to be unique so one thing to check is that you don't have more than one element with an id of "add". If that's not the issue use some debugging techniques to see what is happening. Does your HideInsertNewRowButton function get called? If you view the source of the page do you see your "DisableNewRow();" script on the page? Does DisableNewRow get called? Does "$("#add")" return anything? (check $("#add").length is > 0).
Vincent Maverick Durano 29-Aug-19 16:56pm
Why are you calling a JavaScript function at the server in the first place? Any specific reason for that? Why not call the JavaScript function directly at the client instead?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You can give these a try

register client script block inject after view state

register startup script inject before end of tag

ScriptManager.RegisterClientScriptBlock(Page, GetType(String), "myScriptName" + key, $"yourJsFunctionName({jsObject})", True)

ClientScript.RegisterStartupScript(GetType(),"hwa","alert('Hello World');",true);


ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "Func()", true);

4 Another trick you can try

<head runat="server"> 
  <script type="text/javascript"> 
    function showAlertBox() { 
      alert("Invoked from codebehind."); 
  <form id="form1" runat="server"> 
    <asp:Label ID="lable1" runat="server" Text=""></asp:Label> 
    <asp:Button ID="btnShow" runat="server" Text="Invoke Dialogue" /> 

Code behind to trigger the JavaScript function is here.

lable1.Text = "<script type='text/javascript'>showDialogue();</script>";

One more thing try to put alet('Test'); in your js function, it might be calling the function but not able to find your selector.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100