1: 2:
<asp:Button ID="AddButton" runat="server" Text="Add Barn" UseSubmitBehavior="False" onclick="return validate();"/>
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
function validate() { if (document.getElementById("FNameTextbox").value=="") { alert("First name is required"); document.getElementById("FNameTextbox").focus(); return false; } if (document.getElementById("LNameTextbox").value=="") { alert("Last name is required"); document.getElementById("LNameTextbox").focus(); return false; } if (document.getElementById("BarnNumberTextbox").value=="") { alert("Barn number is required"); document.getElementById("BarnNumberTextbox").focus(); return false; } else return true; }
1: 2: 3: 4: 5:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load AddButton.Attributes.Add("onclick", "return validate()") End Sub