This blog details how to use the validation summary.
Here there are four text box controls. Assume all the fields are mandatory and it will show the validation summary.
Design:
  1. <table cellpadding="0" cellspacing="0" border="0" width="100%">
  2. <tr>
  3. <td>
  4. Name:
  5. </td>
  6. <td>
  7. <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
  8. </td>
  9. </tr>
  10. <tr>
  11. <td>
  12. Address:
  13. </td>
  14. <td>
  15. <asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
  16. </td>
  17. </tr>
  18. <tr>
  19. <td>
  20. City:
  21. </td>
  22. <td>
  23. <asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
  24. </td>
  25. </tr>
  26. <tr>
  27. <td>
  28. State:
  29. </td>
  30. <td>
  31. <asp:TextBox ID="txtState" runat="server"></asp:TextBox>
  32. </td>
  33. </tr>
  34. <tr>
  35. <td>
  36. <asp:Button ID="btnSubmit" runat="server" OnClientClick="return ValidateControls();" Text="Submit" />
  37. </td>
  38. <td>
  39. <asp:Button ID="btnReset" runat="server" Text="Reset" />
  40. </td>
  41. </tr>
  42. </table>
Java Script:
  1. <script type="text/javascript">
  2. function ValidateControls()
  3. {
  4. var txt = "Required to fill the following field(s)";
  5. var opt = 0;
  6. if (document.getElementById('<%=txtName.ClientID %>'))
  7. {
  8. if (document.getElementById('<%=txtName.ClientID %>').value == "")
  9. {
  10. txt += "\n - Name";
  11. var opt = 1;
  12. }
  13. }
  14. if (document.getElementById('<%=txtAddress.ClientID %>'))
  15. {
  16. if (document.getElementById('<%=txtAddress.ClientID %>').value == "")
  17. {
  18. txt += "\n - Address";
  19. var opt = 1;
  20. }
  21. }
  22. if (document.getElementById('<%=txtCity.ClientID %>'))
  23. {
  24. if (document.getElementById('<%=txtCity.ClientID %>').value == "")
  25. {
  26. txt += "\n - City";
  27. var opt = 1;
  28. }
  29. }
  30. if (document.getElementById('<%=txtState.ClientID %>'))
  31. {
  32. if (document.getElementById('<%=txtState.ClientID %>').value == "")
  33. {
  34. txt += "\n - State";
  35. var opt = 1;
  36. }
  37. }
  38. if (opt == "1")
  39. {
  40. alert(txt);
  41. return false;
  42. }
  43. return true;
  44. }
  45. </script>