473,385 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

dropdownlist with customvaliation

Hi

I have a custom validator that validates a dropdownlist with a listitem
value as "". But the clientvalidation function is never called.
but if i use value = "0" and check it in javascript, it works fine. It might
be silly, but it is eating my time. Any Ideas?

for eg:
<asp:DropDownList id=DropDownList1 runat="server">
<asp:ListItem Value="">select</asp:ListItem>
<asp:ListItem Value="1">test1</asp:ListItem>
<asp:ListItem Value="2">test2</asp:ListItem>
</asp:DropDownList>
<asp:CustomValidator id=CustomValidator1 runat="server"
ControlToValidate="DropDownList1" ErrorMessage="errrrrrrr"
ClientValidationFunction="testddl"></asp:CustomValidator>

function testddl(source, arguments) { var ddlDropDownList1 =
document.Form1.DropDownList1.options[document.Form1.DropDownList1.selectedIn
dex].value; if (ddlDropDownList1 == "") { arguments.IsValid = false; } }

Thanks
gane
Nov 19 '05 #1
5 3193
Hey,

This is by Microsoft's design. The only way to get around it is to
write your own custom validator control.

If you look at WebUIValidation.js (in C:\Inetpub) you'll find this
function is being called:

function CustomValidatorEvaluateIsValid(val) {
var value = "";
if (typeof(val.controltovalidate) == "string") {
value = ValidatorGetValue(val.controltovalidate);
if (ValidatorTrim(value).length == 0)
return true;
}
var args = { Value:value, IsValid:true };
if (typeof(val.clientvalidationfunction) == "string") {
eval(val.clientvalidationfunction + "(val, args) ;");
}
return args.IsValid;
}

Notice it returns true (valid) if the value is an empty string.

Oh, btw, welcome to Microsoft hell :).

Nov 19 '05 #2
Hi

Thanks for your valuable input.
is it changed in asp.net 2.0?

Thanks
Gane
<sa*************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hey,

This is by Microsoft's design. The only way to get around it is to
write your own custom validator control.

If you look at WebUIValidation.js (in C:\Inetpub) you'll find this
function is being called:

function CustomValidatorEvaluateIsValid(val) {
var value = "";
if (typeof(val.controltovalidate) == "string") {
value = ValidatorGetValue(val.controltovalidate);
if (ValidatorTrim(value).length == 0)
return true;
}
var args = { Value:value, IsValid:true };
if (typeof(val.clientvalidationfunction) == "string") {
eval(val.clientvalidationfunction + "(val, args) ;");
}
return args.IsValid;
}

Notice it returns true (valid) if the value is an empty string.

Oh, btw, welcome to Microsoft hell :).

Nov 19 '05 #3
You don't need a custom validator for this. Use a RequiredFieldValidator
and set the InitialValue property to "select" (which is your "invalid value"
to validate against).

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi

I have a custom validator that validates a dropdownlist with a
listitem
value as "". But the clientvalidation function is never called.
but if i use value = "0" and check it in javascript, it works fine. It
might
be silly, but it is eating my time. Any Ideas?
for eg:
<asp:DropDownList id=DropDownList1 runat="server">
<asp:ListItem Value="">select</asp:ListItem>
<asp:ListItem Value="1">test1</asp:ListItem>
<asp:ListItem Value="2">test2</asp:ListItem>
</asp:DropDownList>
<asp:CustomValidator id=CustomValidator1 runat="server"
ControlToValidate="DropDownList1" ErrorMessage="errrrrrrr"
ClientValidationFunction="testddl"></asp:CustomValidator>
function testddl(source, arguments) { var ddlDropDownList1 =
document.Form1.DropDownList1.options[document.Form1.DropDownList1.sele
ctedIn dex].value; if (ddlDropDownList1 == "") { arguments.IsValid =
false; } }

Thanks
gane


Nov 19 '05 #4
I agree that using the RequiredFieldValidator with its InitialValue property
is the way to go. I just wanted to correct the statement made below.

By design, the CustomValidator will not get called if the control it is
evaluating has a blank value. So you simply do not assign the
ControlToValidate property. It will now call your evaluation method at all
times and you are responsible for getting the value yourself.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

<sa*************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hey,

This is by Microsoft's design. The only way to get around it is to
write your own custom validator control.

If you look at WebUIValidation.js (in C:\Inetpub) you'll find this
function is being called:

function CustomValidatorEvaluateIsValid(val) {
var value = "";
if (typeof(val.controltovalidate) == "string") {
value = ValidatorGetValue(val.controltovalidate);
if (ValidatorTrim(value).length == 0)
return true;
}
var args = { Value:value, IsValid:true };
if (typeof(val.clientvalidationfunction) == "string") {
eval(val.clientvalidationfunction + "(val, args) ;");
}
return args.IsValid;
}

Notice it returns true (valid) if the value is an empty string.

Oh, btw, welcome to Microsoft hell :).

Nov 19 '05 #5
sam
This is a good point. In fact, if you look at the JS code above, you
can see this for yourself.

I knew this at one point, but who can keep all the catch-alls,
exceptions, and special cases straight? ;).

-Sam

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
2
by: Shiju Poyilil | last post by:
Hello, I have a datagrid with only one row and its having 2 dropdownlists, I need to populate the secodn dropdownlist on the basis of the selection in the first dropdown. but I am not able to...
10
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
15
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
1
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over...
0
by: asmx126453 | last post by:
Hey mensen I am having some big troubles here i tryd solving it myself with internet for 2 days but i kind fix it. Its about this i have a DotNet project that alrydi is online and working for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.