I have a vb.net project where I'm using javascript for server-side control validation.
I am registering the javascript code to validate the controls using a asp button click event. The problems is that I want to stop code execution if validation fails (indicated with an alert).
My code is below:
VB:
Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles cmdSubmit.Click
Dim sscript As New StringBuilder
If (Not ClientScript.IsStartupScriptRegistered("committeeEditorValidator")) Then
Page.ClientScript.RegisterStartupScript(Me.GetType(), "committeeEditorValidator", "committeeEditorValidator();", True)
End If
'Need the Sub routine to stop here if a Javascript alert is thrown.
updateMemberInfo()
End Sub
Javascript:
if (document.committeeEditor.txtbAcronym.value.length < 1)
{
document.getElementById("hderror").value = "1"
alert("You must provide a Committee Acronym!");
document.committeeEditor.txtbAcronym.focus();
return false;
}
document.committeeEditor.submit();
}