Validate DropDownList - Bilal Haidar [MVP]

I just came across this article on how to use a required field validator on a dropdownlist control - I think the beauty of it is it's simplicity:

By setting the Required Field's InitialValue property to be the same as the Dropdownlist's default value, we can force the validator to "kick off" if the value isn't changed.

Thanks to Bilal Haidar for the solution:

<asp:DropDownList id="DropDownList1" runat="server">
    <
asp:ListItem Value="-1">--> Choose <--</asp:ListItem>
    <asp:ListItem Value="1">Lebanon</asp:ListItem>
    <
asp:ListItem Value="2">Kuwait</asp:ListItem>
</asp:DropDownList>

<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="You must select a valid option" ControlToValidate="DropDownList1" InitialValue="-1" Display="Dynamic" />
<P>
    <asp:Button id="Button1" runat="server" Text="Post Back" />
</P>

Validate DropDownList - Bilal Haidar [MVP]

Blogged with the Flock Browser

Tags: , , , ,


Posted by: Dean
Posted on: 4/27/2008 at 5:15 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

Lifes too short

I apologies if this is a bit deep but...

I've just had a rather alarming epiphany; I received a letter on Saturday telling me how much my pension is worth and what date I can expect to get it.  I didn't really take any notice of it at the time, but thinking back I've realised that the date on it is only 20 years away.

I've heard of people having a midlife crisis before now but this has totally knocked me for 6, if I put this together with the date I got from my Death Clock calculation 2047 I've not got much time left to do all the things I've want to do in life.  Eeeek!

It does make me think though, I'd always been of the mind that I'm young - I certainly feel young (if only at heart), it only feels like moments since it was my 23rd birthday. But when I think back properly about the places I've been, the people I've met it seems like a long line of memories. I am also one of the oldest in my workplace, I could never understand before why people treated with me respect (apart from the odd muppet), or valued my opinions, but maybe I should start seeing myself as others see me, have a bit more self respect and stop doubting myself.. and enjoy the life I've got left :0)

Blogged with the Flock Browser

Tags: , , , , , ,


Posted by: Dean
Posted on: 4/6/2008 at 12:54 PM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed