ASPX Page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ValidationsDev.aspx.cs" Inherits="ValidationsDev" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.2, Version=9.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.2, Version=9.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxg" %>
<%@ Register Assembly="DevExpress.Web.v9.2, Version=9.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxTabControl" TagPrefix="dxtc" %>
<%@ Register Assembly="DevExpress.Web.v9.2, Version=9.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPanel" TagPrefix="dxp" %>
<%@ Register Assembly="DevExpress.Web.v9.2, Version=9.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dxrp" %>
<!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>Validations</title>
<script src="Common.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<%--Textbox validation example--%>
<dx:ASPxLabel ID="lblSample" Text="Sample" runat="server" />
<dx:ASPxTextBox ID="txtSample" ClientInstanceName="txtValidate" Width="170px" EnableClientSideAPI="true"
runat="server" OnValidation="txtSample_Validation">
<ValidationSettings SetFocusOnError="True" ErrorText="Name must be at least two characters long">
<ErrorImage Height="16px" Width="16px" AlternateText="Error" />
<RequiredField IsRequired="True" ErrorText="Name is required" />
<ErrorFrameStyle ForeColor="Red">
<Paddings Padding="3px" PaddingLeft="4px" />
<Border BorderColor="#FD4D3E" BorderStyle="Solid" BorderWidth="1px" />
<ErrorTextPaddings PaddingRight="3px" />
</ErrorFrameStyle>
</ValidationSettings>
<ClientSideEvents Validation="OnNameValidation" />
</dx:ASPxTextBox>
<dx:ASPxLabel ID="lblAge" Text="Age" runat="server" />
<dx:ASPxTextBox ID="txtAge" ClientInstanceName="txtAge" EnableClientSideAPI="true"
runat="server" Width="170px" OnValidation="txtAge_Validation">
<ValidationSettings SetFocusOnError="True" ErrorText="Age must be greater than or equal to 18">
<ErrorImage Height="16px" Width="16px" AlternateText="Error" />
<RequiredField IsRequired="True" ErrorText="Age is required" />
<ErrorFrameStyle ForeColor="Red">
<Paddings Padding="3px" PaddingLeft="4px" />
<Border BorderColor="#FD4D3E" BorderStyle="Solid" BorderWidth="1px" />
<ErrorTextPaddings PaddingRight="3px" />
</ErrorFrameStyle>
</ValidationSettings>
<ClientSideEvents Validation="OnAgeValidation" />
</dx:ASPxTextBox>
<%--Combo box example--%>
<dx:ASPxLabel ID="lblCity" Text="City" runat="server" />
<dx:ASPxComboBox ID="cmbxCity" runat="server" ValueType="System.String">
<Items>
<dx:ListEditItem Text="1" Value="1" />
<dx:ListEditItem Text="2" Value="2" />
</Items>
<ValidationSettings SetFocusOnError="true">
<RequiredField ErrorText="City reuired" IsRequired="true" />
<ErrorFrameStyle ForeColor="Red">
<Paddings Padding="3px" PaddingLeft="4px" />
<Border BorderColor="#FD4D3E" BorderStyle="Solid" BorderWidth="1px" />
<ErrorTextPaddings PaddingRight="3px" />
</ErrorFrameStyle>
</ValidationSettings>
</dx:ASPxComboBox>
<br />
<%--Get multiple values in combobox--%>
<dx:ASPxComboBox ID="cmbxMultivalue" runat="server" EnableCallbackMode="True" EnableIncrementalFiltering="True"
CallbackPageSize="10" ValueField="intGlCode" ValueType="System.String" DataSourceID="SqlDataSource1">
<Columns>
<dx:ListBoxColumn FieldName="varAreaName" />
<dx:ListBoxColumn FieldName="varAreaCode" />
<dx:ListBoxColumn FieldName="varAreaHead" />
<dx:ListBoxColumn FieldName="varEmail" />
</Columns>
</dx:ASPxComboBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BASF_1111ConnectionString %>"
SelectCommand="SELECT * FROM [Area_Mst]"></asp:SqlDataSource>
<%--Get selected values in listbox --%>
<dx:ASPxListBox ID="lstbxItems" runat="server" SelectionMode="CheckColumn" DataSourceID="SqlDataSource1">
<Columns>
<dx:ListBoxColumn FieldName="varAreaName" />
<dx:ListBoxColumn FieldName="varAreaHead" />
<dx:ListBoxColumn FieldName="varAreaCode" />
</Columns>
</dx:ASPxListBox>
<%--Gridview on dropdown click--%>
<dx:ASPxDropDownEdit ID="drpEditTest" runat="server">
<DropDownWindowTemplate>
<dxg:ASPxGridView ID="ZoneGrid" DataSourceID="SqlDataSource1" runat="server"
KeyFieldName="ID" Width="100%">
<columns>
<dxg:GridViewDataColumn FieldName="intGlCode" VisibleIndex="0">
</dxg:GridViewDataColumn>
<dxg:GridViewDataColumn FieldName="varAreaCode" VisibleIndex="1">
</dxg:GridViewDataColumn>
<dxg:GridViewDataColumn FieldName="varAreaName" VisibleIndex="2">
</dxg:GridViewDataColumn>
<dxg:GridViewDataTextColumn FieldName="varAreaHead" VisibleIndex="3">
</dxg:GridViewDataTextColumn>
<dxg:GridViewDataColumn FieldName="varEmail" VisibleIndex="4">
</dxg:GridViewDataColumn>
</columns>
</dxg:ASPxGridView>
</DropDownWindowTemplate>
</dx:ASPxDropDownEdit>
<dxg:ASPxGridView ID="ZoneGrid" DataSourceID="SqlDataSource1" runat="server"
KeyFieldName="ID" Width="100%">
<columns>
<dxg:GridViewDataColumn FieldName="intGlCode" VisibleIndex="0">
</dxg:GridViewDataColumn>
<dxg:GridViewDataColumn FieldName="varAreaCode" VisibleIndex="1">
</dxg:GridViewDataColumn>
<dxg:GridViewDataColumn FieldName="varAreaName" VisibleIndex="2">
</dxg:GridViewDataColumn>
<dxg:GridViewDataTextColumn FieldName="varAreaHead" VisibleIndex="3">
</dxg:GridViewDataTextColumn>
<dxg:GridViewDataProgressBarColumn FieldName="Complete" VisibleIndex="4" PropertiesProgressBar-ShowPosition="true">
</dxg:GridViewDataProgressBarColumn>
<dxg:GridViewDataColumn FieldName="varEmail" VisibleIndex="5">
</dxg:GridViewDataColumn>
</columns>
</dxg:ASPxGridView>
<dxrp:ASPxRoundPanel ID="rndpnlSample" runat="server" ShowHeader="False">
<PanelCollection>
<dxp:PanelContent>
<dxtc:ASPxTabControl runat="server" ID="tbSample" DataSourceID="XmlDataSource1">
</dxtc:ASPxTabControl>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml">
</asp:XmlDataSource>
</dxp:PanelContent>
</PanelCollection>
</dxrp:ASPxRoundP nel>
</div>
</form>
</body>
</html>
Code behind page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ValidationsDev : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void txtSample_Validation(object sender, DevExpress.Web.ASPxEditors.ValidationEventArgs e)
{
if ((e.Value as string).Length < 2)
e.IsValid = false;
}
protected void txtAge_Validation(object sender, DevExpress.Web.ASPxEditors.ValidationEventArgs e)
{
string strAge = ((string)e.Value).TrimStart('0');
if (strAge.Length == 0)
return;
UInt32 age = 0;
if (!UInt32.TryParse(strAge, out age) || age < 18)
e.IsValid = false;
}
}