Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CustomValidator not stopping button action

Status
Not open for further replies.
Mar 1, 2001
37
US
I have a customvalidaor that seems to be working and displaying an error message when I click an "Add" button but the code still runs that the "Add" button calls. How do I get the customvalidator to not run the code when I set args.IsValid = False?
 
<asp:Button id="btnLoanCertProfileAdd" onclick="AddLoanCertProfile" runat="server" Width="35px"

<asp:CustomValidator id="ctvNewProfileName" CssClass="ErrorMsg" runat="server" ControlToValidate="txtLoanCertProfileName"
Display="Dynamic" ErrorMessage="Profile Already Exists">*</asp:CustomValidator>


Private Sub ctvNewProfileName_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles ctvNewProfileName.ServerValidate

args.IsValid = False

End Sub


Sub AddLoanCertProfile(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub


 
I have another solution for you, I don´t use the custom validator, when I need do something like that y make a function (functionVal) to validate the values in the form and i returned true or false. And in the vb i add this line in the Page_Load Method

Me.ImageButton.Attributes.Add("OnClick","if (!functionVal();) return false;")
 
I would still like to use the CustomValidator because I use many other validators such as RegularExpressionValidator and RequiredFieldValidator. They work perfect so I would like to figure out what is wrong with my CustomValidator.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top