Thursday, October 20, 2011

Client side Validation on submit with javascript and aspxtextbox

DevExpress controls own validation mechanism. Specify textbox validation group property under validationsettings to string value that you want to use and specify in the ValidationGroup method as parameter.

you can raise validation check from client side event of any button using devepress client side framework as:

OnClientClick="return ASPxClientEdit.ValidateGroup('validationgroupname');

Here is the code snippet to explain:

User Name:
<dxe:ASPxTextBox ID="tbUserName" runat="server" Width="170px">
<ValidationSettings SetFocusOnError="True">
<RequiredField IsRequired="True" ErrorText="User name can't be empty" />
</ValidationSettings>
</dxe:ASPxTextBox>
Password:
<dxe:ASPxTextBox ID="tbPassword" runat="server" Width="170px" Password="True">
<ValidationSettings SetFocusOnError="True">
<RequiredField IsRequired="True" ErrorText="Password can't be empty"
ValidationGroup="MYGroup"/>
</ValidationSettings>
</dxe:ASPxTextBox>
Last Name:
<dxe:ASPxTextBox ID="tbLastName" runat="server" Width="170px">
<ValidationSettings SetFocusOnError="True">
<RequiredField IsRequired="True" ErrorText="Last name can't be empty" />
</ValidationSettings>
</dxe:ASPxTextBox>
First Name:
<dxe:ASPxTextBox ID="tbFirstName" runat="server" Width="170px">
<ValidationSettings SetFocusOnError="True">
<RequiredField IsRequired="True" ErrorText="First name can't be empty" />
</ValidationSettings>
</dxe:ASPxTextBox>
<br />
<asp:Button ID="btnSumbit" runat="server" Text="Submit" OnClientClick="return
ASPxClientEdit.ValidateGroup('MYGroup');" />

Now it will validate on tbPassword. no others because they do not match validationgroup.

No comments :

Post a Comment