Is there a way to pass control IDs from code behind to HTML without knowing the control names in advance due to dynamic generation? The regular method using
MyTextBox = document.getElementById("<%= TextBox1.ClientID %>");
won't work in this scenario.
How can I modify the following code to achieve the desired functionality:
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);");
JS function:
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 < 10) {
day = '0' + day;
}
if (month < 10) {
month = '0' + month;
}
MyTextBox2.value = day + "/" + month + "/" + year;
}