Evento ServerValidate
Si verifica quando la convalida personalizzata consente di convalidare il valore della proprietà ControlToValidate.
public event System.Web.UI.WebControls.ServerValidateEventHandler ServerValidate
Osservazioni
Se viene registrato un metodo con questo evento, esso viene chiamato con il valore della proprietà ControlToValidate. La convalida ha esito positivo solo se il gestore eventi restituisce true.
Esempio
Nell'esempio riportato di seguito viene mostrato come intercettare l'evento ServerValidate per aggiungere la logica per la convalida della pagina.
[Visual Basic]
Protected Sub Submit_OnClick(sender As Object, e As EventArgs)
' Validator checking. If things go wrong, return.
' The validator's error message will be displayed on
' the same panel.
If Page.IsValid Then
ActiveForm = Form2
End If
End Sub
Public Sub ServerValidate(source As Object, args As ServerValidateEventArgs)
Dim num As Integer = Int32.Parse(args.Value)
If num Mod 2 = 0 Then
cust.Text = "Valid number"
args.IsValid = True
Else
cust.Text = "InValid number"
args.IsValid = False
End If
End Sub
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
cust.Alignment = System.Web.UI.MobileControls.Alignment.Center
cust.Wrapping = System.Web.UI.MobileControls.Wrapping.NoWrap
cust.ForeColor = System.Drawing.Color.Blue
cust.StyleReference = "Title"
cust.Display = System.Web.UI.WebControls.ValidatorDisplay.Static
End Sub
<mobile:Form id="Form1" runat=server>
<mobile:Label id="message1" runat=server>
Please enter an Even number
</mobile:Label>
<mobile:TextBox id="number" runat=server MaxLength=9 />
<mobile:CustomValidator ID="cust" ControlToValidate="number"
OnServerValidate="ServerValidate"
runat=server >
Invalid number
</mobile:CustomValidator>
<mobile:Command id="Command1" runat=server OnClick="Submit_OnClick">
Submit
</mobile:Command>
</mobile:Form>
<mobile:Form id="Form2" runat=server>
<mobile:Label id="Label2" runat=server>number is submitted</mobile:Label>
</mobile:Form>
<script language="c#" runat=server>
protected void Submit_OnClick(Object sender, EventArgs e)
{
// Validator checking. If things go wrong, return.
// The validator's error message will be displayed on
// the same panel.
if (Page.IsValid)
{
ActiveForm = Form2;
}
}
public void ServerValidate (object source, ServerValidateEventArgs args)
{
int num = Int32.Parse(args.Value);
if (num % 2 == 0)
{
cust.Text = "Valid number";
args.IsValid = true;
}
else
{
cust.Text = "InValid number";
args.IsValid = false;
}
}
public void Page_Load(Object sender, EventArgs e)
{
cust.Alignment = System.Web.UI.MobileControls.Alignment.Center;
cust.Wrapping = System.Web.UI.MobileControls.Wrapping.NoWrap;
cust.ForeColor = System.Drawing.Color.Blue;
cust.StyleReference = "Title";
cust.Display = System.Web.UI.WebControls.ValidatorDisplay.Static;
}
</script>
<mobile:Form id="Form1" runat=server>
<mobile:Label id="message1" runat=server>
Please enter an Even number
</mobile:Label>
<mobile:TextBox id="number" runat=server MaxLength=9 />
<mobile:CustomValidator ID="cust" ControlToValidate="number"
OnServerValidate="ServerValidate"
runat=server >
Invalid number
</mobile:CustomValidator>
<mobile:Command id="Command1" runat=server OnClick="Submit_OnClick">
Submit
</mobile:Command>
</mobile:Form>
<mobile:Form id="Form2" runat=server>
<mobile:Label id="Label2" runat=server>number is submitted</mobile:Label>
</mobile:Form>
Vedere anche
Classe CustomValidator