[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

Custom validators...

Is there a way to design a custom validator that only presents a warning and will allow the user to continue?

thx.
0
Weller0123
Asked:
Weller0123
  • 2
3 Solutions
 
raterusCommented:
Yes, are we talking about client-side or server-side?

It's always up to you on the server of what to do, you just check Page.IsValid()

On the client, you'd just have to design a message to alert them, but still set the validator valid=true.
0
 
Jeff CertainCommented:
Yes... create a custom validator that sends uses this as the validation function:

window.alert('Warning');
args.IsValid = true;
0
 
Jeff CertainCommented:
raterus...

Using a custom validator does both... at least according to Microsoft**. Specifying the javascript validation function will run client-side scripting if javascript is enabled, and validate server-side (using Page.IsValid)  if javascript is not enabled.

Of course, you know all this already ;)

j

** warning: this claim is made by Microsoft and has not been tested by the author. Like most MS claims, your mileage may vary... ;)
0
 
b1xml2Commented:
<asp:CustomValidator Id="CustomValidator1" runat="server" Display="None" ClientValidationFunction="CustomValidator1_ClientValidate" />
<asp:LinkButton Id="SaveButton" runat="server" CausesValidation="True">Save</asp:LinkButton>

javascript
=======
function CustomValidator1_ClientValidate(sender,args)
{
      bool value = false;
      if (<condition> = true)
      {
            value = true;
      }
      
      
      args.IsValid = value;
      
      if (! value)
      {
            alert(...);
      }
}



VB.NET
=====
Private Sub CustomValidator1_ServerValidate(ByVal sender As Object, ByVal args As ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
      Dim value As Boolean = False
      If <condition> Then
            value = True
      End If
      
      args.IsValid = value
      
      If Not value Then
            Page.RegisterClientScriptBlock("display","<script language=""javascript"">window.onload = function () { alert(...) }</script>")
      End If
End Sub


Private Sub SaveButton_Click(ByVal sender As Object,ByVal e As EventArgs) Handles SaveButton.Click
      Page.Validate()
      If Page.IsValid Then
            'process
      End If
End Sub

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now