Skip to main content

Posts

Showing posts from September, 2010

Complete use of RequiredFieldValidator

It's very common to use asp:RequiredFieldValidator to validate form data before submission. Using this for a TextBox is very straight forward, but Today, I came to know that the same can be used effectively to validate asp:DropDownList and asp:RadioButtonsList too. Lets know, how this can be done. First of all, the usage depends on the Binding of List Items. If all the Items are static and added with <asp:ListItem> as below <asp:DropDownList ID="ddlAddress" Width="150" runat="server"> <asp:ListItem>-select-</asp:ListItem> <asp:ListItem>Item1</asp:ListItem> <asp:ListItem>Item2</asp:ListItem> </asp:DropDownList> Here first item is optional and used for DropDownList in general. Now, the RequiredFieldValidator for this dropdownlist will be as following: <asp:RequiredFieldValidator ID="rfvaAddress" InitialValue="0" ControlToValidate="ddlAddress" runat="se