title: c# asp.net textbox add oninput attribute dynamically
body: <p>I want to make it so my dynamically added textbox calls a javascript function each time the value inside the textbox changes. This works by using the onInput attribute. Can I add this attribute dynamically, somewhere along those lines?</p>
  
  <pre><code>Textbox txt = new TextBox();
  txt.ID = "test";
  txt.Attrubute = onInput("jsfunction()");
  form1.Controls.Add(txt);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>txt.Attributes["onInput"] = "jsfunction()";
  </code></pre>
  
  <p>Thanks in advance :)</p>
  
  <h2>Edit:</h2>
  
  <p>This is my whole code snippet.</p>
  
  <pre><code>pholder.Controls.Add(new LiteralControl("&lt;table&gt;"));
  for (int i = 0; i &lt; dv_inputParameter.Count; i++)
  {
      pholder.Controls.Add(new LiteralControl("&lt;tr&gt;"));
      pholder.Controls.Add(new LiteralControl("&lt;td&gt;"));
      Label lbl = new Label();
      lbl.Text = dv_inputParameter.Table.Rows[i][1].ToString() + " ";
      lbl.ID = "lbl_parameter" + i;
      pholder.Controls.Add(lbl);
      pholder.Controls.Add(new LiteralControl("&lt;/td&gt;"));
  
      pholder.Controls.Add(new LiteralControl("&lt;td&gt;"));
      TextBox txt = new TextBox();
      String tb_id = "tb_parameter" + i;
      txt.ID = tb_id;
      txt.Attributes.Add("onkeyup", String.Format(@"var txt = document.getElementById({0}); var btn = document.getElementById('Btn_Start'); btn.disabled = (txt.value.trim().length == 0)", tb_id));
      pholder.Controls.Add(txt);
      pholder.Controls.Add(new LiteralControl("&lt;/td&gt;"));
      pholder.Controls.Add(new LiteralControl("&lt;/tr&gt;"));
  }
  pholder.Controls.Add(new LiteralControl("&lt;/table&gt;"));
  </code></pre>
  
  <p>I am putting the label and textboxes inside a html table. The function is supposed to make the button with the ID "Btn_Start" clickable as soon as all textboxes have been filled out.</p>