title: javascript pass control names as function parameters
body: <p>I am trying to pass some control IDs from code behind to html but I do not know the control names in advance as they are created dynamically and hence I cannot use something like this: <code>MyTextBox = document.getElementById("&lt;%= TextBox1.ClientID %&gt;");</code></p>
  
  <p>How can I make the following code work (if it is possible that is):</p>
  
  <pre><code>            TextBox test = ((TextBox)e.Row.Cells[7].Controls[0]);
              test.ID = "TextBox1";
              TextBox test2 = ((TextBox)e.Row.Cells[8].Controls[0]);
              test2.ID = "TextBox2";
              test.Attributes.Add("onChange", "javascript:MyFunc(TextBox1, TextBox2);");
  </code></pre>
  
  <p>JS function:</p>
  
  <pre><code>function MyFunc(TextBox1,TextBox2) {
              MyTextBox = document.getElementById("TextBox1");
              MyTextBox2 = document.getElementById("TextBox2");
  
              var splitDate = MyTextBox.value.split('/');
              var date = new Date(splitDate[2], splitDate[1] - 1, splitDate[0]);
  
              var day = date.getDate();
              var month = date.getMonth() + 1;
              var year = date.getFullYear() + 1;
              if (day &lt; 10) {
                  day = '0' + day;
              }
              if (month &lt; 10) {
                  month = '0' + month;
              }
  
              MyTextBox2.value = day + "/" + month + "/" + year;
          }
  </code></pre>