|
 |
|
|
Why not decorate your subclass of ListBox with
[ValidationPropertyAttribute("SelectedValue")]
This will get rid of the ControlToValidate exception.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Set the InitialValue property to a non-emptry string such as "0", "~", something NOT in your valid list. When a postback is attempted the RequiredFieldValidator assigned to the DropDownList will test the Selected.Value against it's InitialValue. If you list is coming from a Stored Procedure, use a union query to return an initial value/text item and then the data itself (ie. SELECT '~', 'None' UNION Select keyID, fldState FROM tblStates) making sure the non-choice's value can sort first in the list. For instance when creating a list of payment methods and an initial non-choice in the form Value, Text ~,(Please choose a payment method) 0,Maxed-Out MasterCard 1,Stolen Visa 2,Discovered in someone's trash Discover 3,Hijacked PayPal Account 4,Counterfiet Money Order 5,Bounced Check 6,Laser-printed Cash
G. Bryant
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
As you provide your DropDownList (DDL and others Lists) with values for each items, there is a validator dedicated to its validation : the RangeValidator.
The only things you have to do is to fill the "blank" item in your DDL with a value "out of range" like "0" or "-1", and the Min and Max properties of the RangeValidator with adequate values (> don't forget to change the "Type" property also, putting "Int" for example when you deal with integer values in your DDL - all casts will be done automatically)
Cheers !
Lord JieM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Arse f**k, why puss us around....
besides what's mentioned below....
change the If to lower case....
include using System.ComponentModel;
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
|
Good job! But as I understood it makes a server side validation. It means you need a postback. It would be graeat to have one with client side javascript validation. Thanks anyway !
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Thank you thank you thank you. I thought I'd never be so happy to see an error message. I'm another guy who programs till 3am over the garage. I struggled with this one for days. This is an elegant solution to a vexing problem. I couldn't find even a mention of the issueon any official Microsoft site.
There are a couple of small, easily discovered and fixed, typos:
The class to inherit from should be System.Web.UI.WebControls.BaseValidator instead of System.Web.UI.BaseValidator
In the EvaluateIsValid override, at two places, instead of _lisctrl.SelectedIndex it should be _listctrl.SelectedIndex
This control can also be modified to have an InitialValue property that it could check instead of SelectedIndex if you want it to behave more like the Microsoft RequiredFieldValidator.
Is there any reasonable way to add a client-side check to mimic the client side code optionally generated by the Microsoft RequiredFieldValidator?
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
It just doesn't work. I get no error messages or anything. Like the control wasn't even there. The other validation controls on the page work ok. When I look at the source of the page from the browser, I can see it put some code in, it is set as hidden. It just doesn't do anything.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Hello prog-fellow...
Good job indeed !
Was looking for a validation for my drop-down list. Didn't really catch your code (did not take time to implement it though, It would have been nice to provide a demo to download...).
Here is how I did :
You populate (Databind) your control normally, Then
add this few lines :
zeDropControl.Items.Insert(0, "---------"); zeDropControl.Items[0].Value = ""; zeDropControl.SelectedIndex = 0;
AND just need to add a normal RequiredField Validator. It works marvels. 
Cheers.
|||Cypher|||
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Positively brilliant. I know I'm late but was having a spot of trouble with this and found the posted solution...however the followup is much simpler. Well done!
Cheers!
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
This solution was the simplest and easist to implement! I was having the same problem with validating dropdownlists, it works like a charm. thanx.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Not bad, I say, not bad. I think I'll give you a 5 now. 7+5=12/3=4
Thus I am improving your rating from 3.5 to 4.0 plus 0.5 cool of me huh?
Nish
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Anytime 
Nish
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |