Alert message not popping up though the dynamic textbox is empty
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.

     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;"); 
        }
      <script language="javascript" type="text/javascript">

    function ValidateMandatoryFields() {
    alert("entered into the function");
    var inputControls = document.getElementsByTagName("input");
    alert(inputControls.length);
    for (var i = 0; i < 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;
                    }
                }
            }
        }
    }
      }
        }
      </script>

[enter link description here][1]  
 i followed the link above


  [1]: http://stackoverflow.com/questions/419769/how-to-validate-dynamically-created-control

Alert message not popping up though the dynamic textbox is empty
===

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.

     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;"); 
        }
      <script language="javascript" type="text/javascript">

    function ValidateMandatoryFields() {
    alert("entered into the function");
    var inputControls = document.getElementsByTagName("input");
    alert(inputControls.length);
    for (var i = 0; i < 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;
                    }
                }
            }
        }
    }
      }
        }
      </script>

[enter link description here][1]  
 i followed the link above


  [1]: http://stackoverflow.com/questions/419769/how-to-validate-dynamically-created-control
