New asp.net/webform user question......
I am trying to use the Custom Validator control to check to see if either of
two fields on my form have been filled in. At this point all I am
interested in is if the user has entered a value into EITHER input box (not
left blank). Below is my control code and also my function. I guess my
question is, What should I be testing for in my function? I have tried many
things (checked the length of the textbox, null, empty string, etc.) and
nothing seems to be working (it returns TRUE).
However, if I test to see if either of the textboxes has a particular value
("1" for example), it works just fine (returns FALSE). So my theroy now is
that I am not testing for null or a empty textbox correctly. What is the
correct test for this?
<asp:CustomValidator runat="server" id="custPhonePagerCheck"
ControlToValidate="txtPhone" OnServerValidate="PhoneNumberCheck"
ErrorMessage="Phone or Pager Number is Required" />
Sub PhoneNumberCheck(sender as Object, args as ServerValidateEventArgs)
If args.value = "" AND txtpager.text = "" Then
args.IsValid = False
Exit Sub
End If
args.IsValid = True
End Sub
Much thanks in advance for any help!
-- Eric 6 2527
You should be able to check for control.text.length != 0 in order to see if
there is user input.
--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--
"EDOnLine" <ed*******@yahooX.com> wrote in message
news:ev*************@tk2msftngp13.phx.gbl... New asp.net/webform user question......
I am trying to use the Custom Validator control to check to see if either
of two fields on my form have been filled in. At this point all I am interested in is if the user has entered a value into EITHER input box
(not left blank). Below is my control code and also my function. I guess my question is, What should I be testing for in my function? I have tried
many things (checked the length of the textbox, null, empty string, etc.) and nothing seems to be working (it returns TRUE).
However, if I test to see if either of the textboxes has a particular
value ("1" for example), it works just fine (returns FALSE). So my theroy now
is that I am not testing for null or a empty textbox correctly. What is the correct test for this?
<asp:CustomValidator runat="server" id="custPhonePagerCheck" ControlToValidate="txtPhone" OnServerValidate="PhoneNumberCheck" ErrorMessage="Phone or Pager Number is Required" />
Sub PhoneNumberCheck(sender as Object, args as ServerValidateEventArgs) If args.value = "" AND txtpager.text = "" Then args.IsValid = False Exit Sub End If args.IsValid = True End Sub Much thanks in advance for any help!
-- Eric
Yeah, that's what I thought too; but it didn't work either. I've tested for
length (.length and length function) and "" and IsDBNull.
What's weird is that if I test for a particular value (the number 1, for
example) it works just fine.
It's probably some simple mistake that I'm making. I am fairly new at this
but it seems that it should work.
Any ideas?
"Chris Jackson" <chrisjATmvpsDOTorgNOSPAM> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... You should be able to check for control.text.length != 0 in order to see
if there is user input.
-- Chris Jackson Software Engineer Microsoft MVP - Windows Client Windows XP Associate Expert -- More people read the newsgroups than read my email. Reply to the newsgroup for a faster response. (Control-G using Outlook Express) --
"EDOnLine" <ed*******@yahooX.com> wrote in message news:ev*************@tk2msftngp13.phx.gbl... New asp.net/webform user question......
I am trying to use the Custom Validator control to check to see if
either of two fields on my form have been filled in. At this point all I am interested in is if the user has entered a value into EITHER input box (not left blank). Below is my control code and also my function. I guess my question is, What should I be testing for in my function? I have tried many things (checked the length of the textbox, null, empty string, etc.) and nothing seems to be working (it returns TRUE).
However, if I test to see if either of the textboxes has a particular value ("1" for example), it works just fine (returns FALSE). So my theroy now is that I am not testing for null or a empty textbox correctly. What is
the correct test for this?
<asp:CustomValidator runat="server" id="custPhonePagerCheck" ControlToValidate="txtPhone" OnServerValidate="PhoneNumberCheck" ErrorMessage="Phone or Pager Number is Required" />
Sub PhoneNumberCheck(sender as Object, args as ServerValidateEventArgs) If args.value = "" AND txtpager.text = "" Then args.IsValid = False Exit Sub End If args.IsValid = True End Sub Much thanks in advance for any help!
-- Eric
EDOnLine wrote: New asp.net/webform user question......
I am trying to use the Custom Validator control to check to see if either of two fields on my form have been filled in. At this point all I am interested in is if the user has entered a value into EITHER input box (not left blank). Below is my control code and also my function. I guess my question is, What should I be testing for in my function? I have tried many things (checked the length of the textbox, null, empty string, etc.) and nothing seems to be working (it returns TRUE).
However, if I test to see if either of the textboxes has a particular value ("1" for example), it works just fine (returns FALSE). So my theroy now is that I am not testing for null or a empty textbox correctly. What is the correct test for this?
<asp:CustomValidator runat="server" id="custPhonePagerCheck" ControlToValidate="txtPhone" OnServerValidate="PhoneNumberCheck" ErrorMessage="Phone or Pager Number is Required" />
Sub PhoneNumberCheck(sender as Object, args as ServerValidateEventArgs) If args.value = "" AND txtpager.text = "" Then args.IsValid = False Exit Sub End If args.IsValid = True End Sub
The CustomValidator validation handler doesn't get called if the control
it's validating (txtPhone in your example) is empty. So, I suspect that
what you're seeing is not that your validation handler is returning True
when both textboxes are empty, but that your validation handler is not
being called at all. This is a behavior that catches a lot of people
the first time they try using a custom validator.
What you want to do is *not* specify a ControlToValidate in your
CustomValidator control (CustomValidators are the only validation
control where a ControlToValidate does not need to be specified).
Then, change your handler slightly to have this line for the test:
If txtPhone.text = "" And txtPager.Text = "" Then
since the args parameter will not have any useful information (because
there's no ControlToValidate).
Now your CustomValidator's OnServerValidate handler will be called every
time the form is posted back to the server.
--
mikeb
EDOnLine wrote: New asp.net/webform user question......
I am trying to use the Custom Validator control to check to see if either of two fields on my form have been filled in. At this point all I am interested in is if the user has entered a value into EITHER input box (not left blank). Below is my control code and also my function. I guess my question is, What should I be testing for in my function? I have tried many things (checked the length of the textbox, null, empty string, etc.) and nothing seems to be working (it returns TRUE).
However, if I test to see if either of the textboxes has a particular value ("1" for example), it works just fine (returns FALSE). So my theroy now is that I am not testing for null or a empty textbox correctly. What is the correct test for this?
<asp:CustomValidator runat="server" id="custPhonePagerCheck" ControlToValidate="txtPhone" OnServerValidate="PhoneNumberCheck" ErrorMessage="Phone or Pager Number is Required" />
Sub PhoneNumberCheck(sender as Object, args as ServerValidateEventArgs) If args.value = "" AND txtpager.text = "" Then args.IsValid = False Exit Sub End If args.IsValid = True End Sub
The CustomValidator validation handler doesn't get called if the control
it's validating (txtPhone in your example) is empty. So, I suspect that
what you're seeing is not that your validation handler is returning True
when both textboxes are empty, but that your validation handler is not
being called at all. This is a behavior that catches a lot of people
the first time they try using a custom validator.
What you want to do is *not* specify a ControlToValidate in your
CustomValidator control (CustomValidators are the only validation
control where a ControlToValidate does not need to be specified).
Then, change your handler slightly to have this line for the test:
If txtPhone.text = "" And txtPager.Text = "" Then
since the args parameter will not have any useful information (because
there's no ControlToValidate).
Now your CustomValidator's OnServerValidate handler will be called every
time the form is posted back to the server.
--
mikeb
Thanks for pointing that out!
So are you saying that the args paramater is useless now? If so, how am I
suppose to tell the validator that it failed the test?
I'm asking that because now, no matter what I put in either textbox, I
always get a FALSE. And after the post back the values that I put in the
boxes are no longer there. Weird. Below is the current version of my
code....
Thanks in advance for any pointers! (Man, I'm going to go nuts before I
learn all of this!)
<asp:CustomValidator runat="server" id="custPhonePagerCheck"
OnServerValidate="PhoneNumberCheck" ErrorMessage="Phone or Pager Number is
Required" />
Sub PhoneNumberCheck(sender as Object, args as ServerValidateEventArgs)
If txtPager.text = "" And txtPhone.text = "" Then
args.IsValid = False
Exit Sub
End If
args.IsValid = True
End Sub The CustomValidator validation handler doesn't get called if the control it's validating (txtPhone in your example) is empty. So, I suspect that what you're seeing is not that your validation handler is returning True when both textboxes are empty, but that your validation handler is not being called at all. This is a behavior that catches a lot of people the first time they try using a custom validator.
What you want to do is *not* specify a ControlToValidate in your CustomValidator control (CustomValidators are the only validation control where a ControlToValidate does not need to be specified).
Then, change your handler slightly to have this line for the test:
If txtPhone.text = "" And txtPager.Text = "" Then
since the args parameter will not have any useful information (because there's no ControlToValidate).
Now your CustomValidator's OnServerValidate handler will be called every time the form is posted back to the server.
-- mikeb
EDOnLine wrote: Thanks for pointing that out!
So are you saying that the args paramater is useless now? If so, how am I suppose to tell the validator that it failed the test?
I'm asking that because now, no matter what I put in either textbox, I always get a FALSE. And after the post back the values that I put in the boxes are no longer there. Weird. Below is the current version of my code....
Thanks in advance for any pointers! (Man, I'm going to go nuts before I learn all of this!)
<asp:CustomValidator runat="server" id="custPhonePagerCheck" OnServerValidate="PhoneNumberCheck" ErrorMessage="Phone or Pager Number is Required" />
Sub PhoneNumberCheck(sender as Object, args as ServerValidateEventArgs)
If txtPager.text = "" And txtPhone.text = "" Then args.IsValid = False Exit Sub End If
args.IsValid = True
End Sub
This validation handler works for me.
I think you're going to have to post more code - try to cut it down to
the smallest possible ASPX page that reproduces the problem.
What tools are you using? if you're using VS.NET then debugging this
should be pretty easy. If you're not using VS.NET, then using the
Framework SDK's CLR Debugger (dbgclr.exe) is almost as good. Note that
dbgclr.exe is not in the path by default - it's in the GuiDebug folder
of the Framework's directory.
The CustomValidator validation handler doesn't get called if the control it's validating (txtPhone in your example) is empty. So, I suspect that what you're seeing is not that your validation handler is returning True when both textboxes are empty, but that your validation handler is not being called at all. This is a behavior that catches a lot of people the first time they try using a custom validator.
What you want to do is *not* specify a ControlToValidate in your CustomValidator control (CustomValidators are the only validation control where a ControlToValidate does not need to be specified).
Then, change your handler slightly to have this line for the test:
If txtPhone.text = "" And txtPager.Text = "" Then
since the args parameter will not have any useful information (because there's no ControlToValidate).
Now your CustomValidator's OnServerValidate handler will be called every time the form is posted back to the server.
-- mikeb
--
mikeb This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bob Cottis |
last post by:
I am getting wierd behaviour with IsNull in ASP. I am
passing a string (which may be null) to a function. When
the string is null, IsNull seems to return false the
first time it is called, then...
|
by: Steven Scaife |
last post by:
I have a quick question i tried searching google but couldn't find anything
What is the difference between not isnull(val) and <> ""
can this statement be reduced from
If NumberDep <> "" or...
|
by: Regnab |
last post by:
I'm trying to test a recordset to see if the SQL query is returning a
Null value. However, the IsNull() test always returns a 'False'
response. I even tried:
Dim NullCheck As String
NullCheck =...
|
by: Brent |
last post by:
I'm trying to keep the logic of my web pages to a minimum. One of the
problems I face regularly is dealing with DBNull's. I know how to code my
way out of them, but I thought perhaps it'd be easier...
|
by: Jan Nielsen |
last post by:
Hi
I am working with rowfilters in dataviews.
I would like to filter for empty fields (= null value in the database)
I found this sentence on msdn:
****************
To return only those columns...
|
by: Laphan |
last post by:
Hi all
In my functions I'm using a double-check all the time to trap if a value has
nothing in it and my question is do I need this double-check.
My check line is:
IF IsNull(xxx) OR...
|
by: Paul Spratley |
last post by:
Hi all
Firstly this my first time posting to technical groups - so any
mistakes I apologise for in advance.
I am trying to count records in several secondary tables for the same
run in a...
|
by: Raoul Watson |
last post by:
I have used isNull statement for as long as I have used VB..
Recently I am devugging a program and it is very clear that the "IsNull"
function sometimes would return a true even when the value is...
|
by: madeleine |
last post by:
Please can someone help me, I think I may go mad with this one:
Do While Not IsNull(CDate(FormatDateTime(rst!F1.Value, vbShortDate)))
If IsNull(CDate(FormatDateTime(rst!F1.Value, vbShortDate)))...
|
by: PW |
last post by:
Hi All,
I go into debug mode with the code below and varReturnVal is Null, but
the code still is run.
Any idea why?
Dim varReturnVal As Variant
Dim intDogID As Integer
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
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,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |