473,385 Members | 1,752 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.

Validating for Empty Listbox

I recently found out that the RequiredFieldValidator works differently
for a ListBox than I needed; it checks to see if a row is selected,
rather than checking to see if the listbox is empty. I tried using a
CustomValidator but it does not seem to be firing (I have e.false in
the validation function but still no intervention). Does the
CustomValidator also require that a row is selected? Can I use
validators for this requirement or do I have to find some other way?

Jul 2 '07 #1
4 9360
Dave wrote:
I recently found out that the RequiredFieldValidator works differently
for a ListBox than I needed; it checks to see if a row is selected,
rather than checking to see if the listbox is empty. I tried using a
CustomValidator but it does not seem to be firing (I have e.false in
the validation function but still no intervention). Does the
CustomValidator also require that a row is selected? Can I use
validators for this requirement or do I have to find some other way?
Maybe I'm missing something here, but the number of items in a listbox is
not something the user can change (unless you have written extra code for
it).
Therefore, it's not supposed to be validated.

The CustomValidator does not know anything about selected rows.
In fact it doesn't know anything about your controls. You don't even have to
set the ControlToValidate property.
You are supposed to write code for the custom validator, and in that code
you can validate what you want.

--

Riki
Jul 2 '07 #2
On Jul 2, 9:49 am, "Riki" <r...@dontnagme.comwrote:
Dave wrote:
I recently found out that the RequiredFieldValidator works differently
for a ListBox than I needed; it checks to see if a row is selected,
rather than checking to see if the listbox is empty. I tried using a
CustomValidator but it does not seem to be firing (I have e.false in
the validation function but still no intervention). Does the
CustomValidator also require that a row is selected? Can I use
validators for this requirement or do I have to find some other way?

Maybe I'm missing something here, but the number of items in a listbox is
not something the user can change (unless you have written extra code for
it).
Therefore, it's not supposed to be validated.

The CustomValidator does not know anything about selected rows.
In fact it doesn't know anything about your controls. You don't even have to
set the ControlToValidate property.
You are supposed to write code for the custom validator, and in that code
you can validate what you want.

--

Riki
I must be doing something messed up then. It does not seem to want to
fire...

HTML:

<asp:ListBox ID="FB" Width="95%" runat="server" font-
size="Small" rows="5"></asp:ListBox>
<asp:CustomValidator ID="CustomValidator1"
runat="server"
Display="Dynamic"
OnServerValidate="Validate_Files"
Text="* Please upload files."
runat="server"/>

ASP FUNCTION:

private void Validate_Files(object sender, ServerValidateEventArgs
e)
{
e.IsValid = false; // Just Testing!
}
But I do not get the error message like I expected. I have other
RequiredFieldValidator's on the page that work. On a side note, there
is also the issue of wierd behavior -- after a
window.location.replace(...) or refresh the validation function does
fire for some reason I don't understand (the only time it does). But
the page can still be submitted no matter what.
Jul 2 '07 #3
you only supplied server code, so the postback will happen. you must
take some action, say check isvalid, and not perform any actions to see
the message.

-- bruce (sqlwork.com)

Dave wrote:
On Jul 2, 9:49 am, "Riki" <r...@dontnagme.comwrote:
>Dave wrote:
>>I recently found out that the RequiredFieldValidator works differently
for a ListBox than I needed; it checks to see if a row is selected,
rather than checking to see if the listbox is empty. I tried using a
CustomValidator but it does not seem to be firing (I have e.false in
the validation function but still no intervention). Does the
CustomValidator also require that a row is selected? Can I use
validators for this requirement or do I have to find some other way?
Maybe I'm missing something here, but the number of items in a listbox is
not something the user can change (unless you have written extra code for
it).
Therefore, it's not supposed to be validated.

The CustomValidator does not know anything about selected rows.
In fact it doesn't know anything about your controls. You don't even have to
set the ControlToValidate property.
You are supposed to write code for the custom validator, and in that code
you can validate what you want.

--

Riki

I must be doing something messed up then. It does not seem to want to
fire...

HTML:

<asp:ListBox ID="FB" Width="95%" runat="server" font-
size="Small" rows="5"></asp:ListBox>
<asp:CustomValidator ID="CustomValidator1"
runat="server"
Display="Dynamic"
OnServerValidate="Validate_Files"
Text="* Please upload files."
runat="server"/>

ASP FUNCTION:

private void Validate_Files(object sender, ServerValidateEventArgs
e)
{
e.IsValid = false; // Just Testing!
}
But I do not get the error message like I expected. I have other
RequiredFieldValidator's on the page that work. On a side note, there
is also the issue of wierd behavior -- after a
window.location.replace(...) or refresh the validation function does
fire for some reason I don't understand (the only time it does). But
the page can still be submitted no matter what.

Jul 2 '07 #4
On Jul 2, 10:23 am, Dave <onlinef...@gmail.comwrote:
On Jul 2, 9:49 am, "Riki" <r...@dontnagme.comwrote:


Dave wrote:
I recently found out that the RequiredFieldValidator works differently
for a ListBox than I needed; it checks to see if a row is selected,
rather than checking to see if the listbox is empty. I tried using a
CustomValidator but it does not seem to be firing (I have e.false in
the validation function but still no intervention). Does the
CustomValidator also require that a row is selected? Can I use
validators for this requirement or do I have to find some other way?
Maybe I'm missing something here, but the number of items in a listbox is
not something the user can change (unless you have written extra code for
it).
Therefore, it's not supposed to be validated.
The CustomValidator does not know anything about selected rows.
In fact it doesn't know anything about your controls. You don't even have to
set the ControlToValidate property.
You are supposed to write code for the custom validator, and in that code
you can validate what you want.
--
Riki

I must be doing something messed up then. It does not seem to want to
fire...

HTML:

<asp:ListBox ID="FB" Width="95%" runat="server" font-
size="Small" rows="5"></asp:ListBox>
<asp:CustomValidator ID="CustomValidator1"
runat="server"
Display="Dynamic"
OnServerValidate="Validate_Files"
Text="* Please upload files."
runat="server"/>

ASP FUNCTION:

private void Validate_Files(object sender, ServerValidateEventArgs
e)
{
e.IsValid = false; // Just Testing!
}

But I do not get the error message like I expected. I have other
RequiredFieldValidator's on the page that work. On a side note, there
is also the issue of wierd behavior -- after a
window.location.replace(...) or refresh the validation function does
fire for some reason I don't understand (the only time it does). But
the page can still be submitted no matter what.- Hide quoted text -

- Show quoted text -
I figured it out. Needed to use ClientValidationFunction instead of
ServerValidationFunction. Sorry about posting the bad code.

Thanks.

Jul 2 '07 #5

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

Similar topics

30
by: Toni Mcintyre | last post by:
i'm having 2 problems with the http://validator.w3.org 1. if i have: <meta http-equiv="Content-Script-Type" content="text/javascript"> then why do i need <script type=text/javascript>...
1
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. ...
6
by: AAJ | last post by:
Hi all I have a listbox on a form. If I set its rowsource directly, and the query in the rowsourse returns no data, then the displayed listbox is empty (exactly as you would expect) ...
3
by: Pafo007 | last post by:
Hi. I've built a small window, with some buttons and labels, and one listbox. During design time, I put five lines in the listbox and launch the program: the listbox appears empty! I can select...
4
by: Eric | last post by:
Is there a way to cancel the validating event on the closing event? I have 2 textboxes that I use the validating event to check for numeric data. If I try to close the form without putting a...
3
by: Husam | last post by:
Hi EveryBody: I made project by Vb.Net which consist the following items: 1\ Textbox 2\Button 3\Listbox When you write any thing in the textbox and press the button any text written in...
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
2
by: lrheeza | last post by:
Hello everyone, I am a newbie at MS Access and I need help!!! I am importing an excel file using Import functionality in MS Access, all the fields are required but there are instances in the...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.