<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
TimePicker1.Items.AddTimes(new TimeSpan(9, 0, 0), new TimeSpan(18, 0, 0), 60);
TimePicker1.Items.Add(new PeterBlum.DES.Web.WebControls.SpecialTimeNoValue("None"));
if (!IsPostBack)
{
DataList1.DataSource = CreateDataSource();
DataList1.DataBind();
}
}
protected ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("Item", typeof(Int32)));
dt.Columns.Add(new DataColumn("Qty", typeof(Int32)));
dt.Columns.Add(new DataColumn("Price", typeof(double)));
for (int i = 0; i < 9; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = i * 2;
dr[2] = 1.23 * (i + 1);
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
return dv;
}
protected void Item_Command(Object sender, DataListCommandEventArgs e)
{
DataList1.SelectedIndex = e.Item.ItemIndex;
DataList1.DataSource = CreateDataSource();
DataList1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (PeterBlum.DES.Globals.WebFormDirector.IsValid)
{
}
}
protected void Button2_Click(object sender, EventArgs e)
{
PeterBlum.DES.Globals.WebFormDirector.Validate();
if (PeterBlum.DES.Globals.WebFormDirector.IsValid)
{
}
}
</script>
Start by clicking Submit to see existing errors. Notice that the last example of a DataList
does not report an error because it only uses server side validation.<br/>
<des:Button ID="Button3" runat="server" Text="Submit" OnClick="Button1_Click"></des:Button>
<br/>
<h2>DES Calendar</h2>
<des:Calendar ID="Calendar1" runat="server">
<ClearCommand ShowField="RecommendedRow" />
</des:Calendar>
<des:RequiredSelectionValidator ID="RSV1" runat="server"
ControlIDToEvaluate="Calendar1"
ErrorMessage="Required" />
<br/>
<br/>
<h2>TimePicker</h2>
<des:TimePicker ID="TimePicker1" runat="server" >
</des:TimePicker>
<des:RequiredSelectionValidator ID="RequiredSelectionValidator1" runat="server"
ControlIDToEvaluate="TimePicker1"
ErrorMessage="Required" />
<br/>
<br/>
<h2>MonthYearPicker</h2>
<des:MonthYearPicker ID="MonthYearPicker1" runat="server" Format="FewYears">
</des:MonthYearPicker>
<des:RequiredSelectionValidator ID="RequiredSelectionValidator2" runat="server"
ControlIDToEvaluate="MonthYearPicker1"
ErrorMessage="Required" ShowRequiredFieldMarker="true" />
<br/>
<br/>
<h2>MultiSelectionCalendar</h2>
<des:MultiSelectionCalendar ID="MultipleSelectionCalendar1" runat="server">
</des:MultiSelectionCalendar>
<des:RequiredSelectionValidator ID="RequiredSelectionValidator4" runat="server"
ControlIDToEvaluate="MultipleSelectionCalendar1"
ErrorMessage="Required" />
<br/>
<br/>
<h2>DataList</h2>
Requires server side validation. Use the "Submit Server side validation only" to see the error. Then click a Select button
to remove the error.<br/>
<asp:DataList ID="DataList1" runat="server" DataKeyField="Item"
GridLines="Both" CellPadding="3" CellSpacing="0" OnItemCommand="Item_Command" >
<HeaderStyle BackColor="#aaaadd" />
<AlternatingItemStyle BackColor="Gainsboro" />
<SelectedItemStyle BackColor="Yellow" />
<HeaderTemplate>
Items
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="SelectButton" Text="Select" CommandName="Select" runat="server" />
Item <%# DataBinder.Eval(Container.DataItem, "Item")%>
</ItemTemplate>
<SelectedItemTemplate>
Item: <asp:Label ID="ItemLabel" Text='<%# DataBinder.Eval(Container.DataItem, "Item")%>'
runat="server" />
<br/>
Quantity: <asp:Label ID="QtyLabel" Text='<%# DataBinder.Eval(Container.DataItem, "Qty")%>'
runat="server" />
<br/>
Price: <asp:Label ID="PriceLabel" Text='<%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}")%>'
runat="server" />
</SelectedItemTemplate>
</asp:DataList>
<des:RequiredSelectionValidator ID="RequiredSelectionValidator5" runat="server"
ControlIDToEvaluate="DataList1"
ErrorMessage="Required" />
<br/><br/>
<des:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"></des:Button>
<des:Button ID="Button2" runat="server" Text="Submit Server side validation only" OnClick="Button2_Click" CausesValidation="false"></des:Button>