Dec 18, 2010, 8:54 AM
RemoteValidation Versus Codebehind
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
Overloads Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextField1.Text = "123"
End Sub
Sub ValidateText(ByVal sender As Object, ByVal e As RemoteValidationEventArgs)
Dim field As TextField = TryCast(sender, TextField)
e.Success = (field.Text = "123")
e.ErrorMessage = "Invalid field"
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" />
<ext:FormPanel ID="FormPanel1" runat="server" Title="Test Form" Border="true" Width="400"
Height="100" MonitorValid="true" Layout="Form" Padding="5">
<Items>
<ext:TextField ID="TextField1" runat="server" MsgTarget="Qtip" AllowBlank="false"
FieldLabel="Text Field 1" Width="220" MaxLength="50" IsRemoteValidation="true">
<RemoteValidation OnValidation="ValidateText" />
</ext:TextField>
</Items>
<Buttons>
<ext:Button ID="SaveButton" runat="server" Text="Save">
<Listeners>
<Click Handler="if (!#{FormPanel1}.getForm().isValid()){Ext.Msg.show({icon: Ext.MessageBox.ERROR, msg: 'FormPanel is incorrect', buttons:Ext.Msg.OK});}" />
</Listeners>
</ext:Button>
<ext:Button ID="Button2" runat="server" Text="Cancel" />
</Buttons>
<Listeners>
<ClientValidation Handler="el.getBottomToolbar().setStatus({text : valid ? 'Form is valid' : 'Form is invalid', iconCls: valid ? 'icon-accept' : 'icon-exclamation'});" />
</Listeners>
</ext:FormPanel>
</form>
</body>
</html>
ScnenarioA form with a text field "TextField1" should only allow "123" as valid value, which is checked by RemoteValidation "ValidateText".
<ext:TextField ID="TextField1" runat="server" MsgTarget="Qtip" AllowBlank="false"
FieldLabel="Text Field 1" Width="220" MaxLength="50" IsRemoteValidation="true">
<RemoteValidation OnValidation="ValidateText" />
</ext:TextField>
Sub ValidateText(ByVal sender As Object, ByVal e As RemoteValidationEventArgs)
Dim field As TextField = TryCast(sender, TextField)
e.Success = (field.Text = "123")
e.ErrorMessage = "Invalid field"
End Sub
ProblemEven when "TextField1" is assigned a valid value from codebehind, the "FormPanel is inocorrect".
Overloads Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextField1.Text = "123"
End Sub
Please help!
Last edited by NickBin; Dec 18, 2010 at 8:57 AM.