title: How to write Javascript coding in C# code behind?
body: <p>i am creating textboxes dynamically so how to call below javascript function for textbox 'onchange' event?</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      debugger;
      function myFunction() {
          var btn = document.getElementById('&lt;%= temp.ClientID%&gt;').value;
          var btntemp = document.getElementById('&lt;%= txttemp2.ClientID%&gt;').value;
          var val = parseInt(btn) + parseInt(btntemp);
          document.getElementById('&lt;%= TextBox1.ClientID%&gt;').value = val;
      }        
  &lt;/script&gt;
  &lt;asp:TextBox ID="temp" runat="server" onchange="myFunction()"&gt;&lt;/asp:TextBox&gt;
     &lt;asp:TextBox ID="txttemp2" runat="server" onchange="myFunction()"&gt;&lt;/asp:TextBox&gt;
  </code></pre>
  
  <p>Here iam creating textboxex dynamically.</p>
  
  <pre><code>Table table = (Table)this.Page.FindControl("PlaceHolder1").FindControl("Table1");
  for (int i = 0; i &lt; rowsCount; i++)
   {
     for (int j = 0; j &lt; colsCount; j++)
      {
       TextBox tb = (TextBox)table.Rows[i + 1].Cells[j].FindControl("TextBoxRow_" + i + "Col_" + j);
       tb.Text = Request.Form["TextBoxRow_" + i + "Col_" + j];
  </code></pre>
  
  <p>here iam getting first column's textbox value</p>
  
  <pre><code>else if (j == 2)
   {
     int quantityText;
     TextBox quantity = (TextBox)table.Rows[i +1].Cells[j].FindControl("TextBoxRow_" + i + "Col_" + j);
  </code></pre>
  
  <p>here iam getting second column's textboxes value </p>
  
  <pre><code>else if (j == 3)
    {
      double rateText;
      TextBox rate = (TextBox)table.Rows[i + 1].Cells[j].FindControl("TextBoxRow_" + i + "Col_" + j);
  </code></pre>
  
  <p>here iam generating textboxes dynamically. </p>
  
  <pre><code>private void GenerateTable(int rowsCount)
   {
    Table table = new Table();
              table.ID = "Table1";
              PlaceHolder1.Controls.Add(table);
             for (int i = 0; i &lt; rowsCount; i++)
              {
                  TableRow row = new TableRow();
                  row.ID = "Row_" + i;
                  else if (j &lt; colsCount - 1)
                      {
                          TableCell cell = new TableCell();
                          TextBox tb = new TextBox();
                        tb.ID = "TextBoxRow_" + i + "Col_" + j;
                        cell.Controls.Add(tb);
                       row.Cells.Add(cell);
                      }
  </code></pre>