Alert message not popping up though the dynamic textbox is empty
<p><br>
Below is the code how I am creating the dynamic textboxes. I want to validate if any of the dynamic textboxes created are empty and if yes, should throw an error message or alert to user prompting to fill up the textboxes on Additem button click. I get the alert message entered into teh funtion, after which I dont receive any message alerting the user to fill in the textbox "xxxx".</p>

<p>Please help me to fix teh code</p>

<pre><code> if (ControlType == "TextBox")
        {
            int textBoxLength;
            TextBox MynewTextBox = new TextBox();
            MynewTextBox.ID = "txt" + Fldname;

            MynewTextBox.Width = 100;
            MynewTextBox.BorderStyle = BorderStyle.Solid;
            MynewTextBox.Attributes.Add("Type", "T");
            MynewTextBox.Attributes.Add("IsKeyField", "Y");
            MynewTextBox.Attributes.Add("IsMandatory", "Y");  
        }



protected void Page_Load(object sender, EventArgs e)
    {    
     btnAddItem.Attributes.Add("onClick", "if(!ValidateMandatoryFields()) return false;"); 
    }
  &lt;script language="javascript" type="text/javascript"&gt;

function ValidateMandatoryFields() {
alert("entered into the function");
var inputControls = document.getElementsByTagName("input");
alert(inputControls.length);
for (var i = 0; i &lt; inputControls.length; i++) {

    if (inputControls[i].getAttribute("IsKeyField") == "Y") {
        if (inputControls[i].getAttribute("Type") == "T" || (inputControls[i].getAttribute("Type") == "C")) {
            if (inputControls[i].getAttribute("IsMandatory") == "Y") {
                if (inputControls[i].value == "") {
                    alert(inputControls[i].getAttribute("KeyField_Name") + "is required.");
                    errorMsg += "\n" + inputControls[i].getAttribute("KeyField_Name") + " is required.";
                    isValidated = false;
                }
            }
        }
    }
}
  }
    }
  &lt;/script&gt;
</code></pre>

<p><a href="http://stackoverflow.com/questions/419769/how-to-validate-dynamically-created-control">enter link description here</a><br>
 i followed the link above</p>

<p>It still did not help me </p>

<pre><code>function ValidateMandatoryFields() {
alert("entered into the function");
var inputControls = document.getElementsByTagName("input");
alert(inputControls.length);
for (var i = 0; i &lt; inputControls.length; i++) {

    if (inputControls[i].getAttribute("IsKeyField") == "Y") {
        alert(inputControls[i]);
    }
    else {
        alert("first if statemenet");
    }

    if (inputControls[i].getAttribute("Type") == "T" || (inputControls[i].getAttribute("Type") == "C")) {
        alert(inputControls[i]);
    }
    else {
        alert("second if statement");
    }
    if (inputControls[i].getAttribute("IsMandatory") == "Y") {
        alert(inputControls[i]);
    }
    else {
        alert("third if statement");
    }

    if (inputControls[i].value == "") {
        alert(inputControls[i].getAttribute("KeyField_Name") + "is required.");--error here
        errorMsg += "\n" + inputControls[i].getAttribute("KeyField_Name") + " is required.";
        isValidated = false;
    }
    else {
        alert("name: " + inputControls[i].id);
        alert("length: " + inputControls[i].value.length());
        alert("value: " + inputControls[i].value);
    }
}
</code></pre>

<p>}</p>

<p>It pop ups of all else statements appear and finally i get a error stating Microsoft JScript runtime error: Object expected. Which means that none of my if condition is true...How do I get it to work...please help me with the correct logic </p>
