title: How to call Javascript function from server side asp.net
body: <p>I have a <code>Textbox</code> in <code>GridView</code> I want to change the Label.Text if the text in Textbox is changed. But I am not able call javascript function written in .cs page. Is there any mistake in <code>TbUnitCost_TextChanged</code> method. </p>
  
  <p>This is my aspx page</p>
  
  <pre><code>&lt;ItemTemplate&gt;
    &lt;asp:TextBox Style="text-align: right" ID="TbUnitCost" runat="server" Width="80px" Text='&lt;%#Bind("Unit_Cost")%&gt;' AutoPostBack="true" OnTextChanged="TbUnitCost_TextChanged"  TextMode="Number"&gt;&lt;/asp:TextBox&gt;
   &lt;/ItemTemplate&gt;
  </code></pre>
  
  <p>Code behind Page is as follows</p>
  
  <pre><code> protected void TbUnitCost_TextChanged (object sender, EventArgs e)
      {
          GridViewRow currentRow = (GridViewRow)((TextBox)sender).Parent.Parent;
          int rowNo = currentRow.RowIndex;
          string gridName = "GridWorkExpenses";
          TextBox tbunitCost = (TextBox)currentRow.FindControl("TbUnitCost");
          int row = Convert.ToInt32(tbunitCost.Text);
  
          tbunitCost.Attributes.Add("onchange","javascript:calculateTotalCost('"+rowNo+"','"+gridName+"');");
  
      }
  </code></pre>
  
  <p>and javascript Function is:</p>
  
  <pre><code>&lt;script type ="text/javascript"&gt;
      function calculateTotalCost(rowNo, GridName) {                        
  
          if (GridName== 'GridWorkExpenses') {
              var rowscount = document.getElementById('&lt;%=GridWorkExpensesSheet.ClientID%&gt;').rows.length;
              return calculateTotalUnitCost("GridWorkExpensesSheet", rowscount,rowNo);
          }
     }
   &lt;/script&gt;     
  </code></pre>