Hi, I have a text box with corresponding comparevalidator as so..
<tr><td align="right">End Date :</td>
<td><asp:TextBox id="dtEndDate" runat="server" onTextChanged="set_Duration"
autopostback="true" cssClass="mandatory"/></td>
<td><asp:CompareValidator id="vdEndDate" runat="server"
cssClass="ErrorMessage" ControlToValidate="dtEndDate" Type="Date"
Operator="DataTypeCheck" ErrorMessage="Incorrect date format"/>
</td></tr>
As you can see when the user changes the text in dtEndDate, i want some code
to fire. However I only want this code to fire if they have entered a correct
date format, tested by vdEndDate, my validator control. So in my script to
fire I have this:
public void set_Duration(Object sender, EventArgs e) {
if (vdEndDate.IsValid) {
blah blah
}
}
But when i put in a silly date and exit the field, the code still fires and
errors coz my date format is wrong for the code i've written. Why is it not
escaping the if condition?? I even see the validator control error message
pop up briefly before it bombs. So surely vdEndDate is not valid when it
enters my code???? 6 1997
Should that not be
if ( e.IsValid )
{
//....
}
instead of vdEndDate?
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:E1**********************************@microsof t.com... Hi, I have a text box with corresponding comparevalidator as so..
<tr><td align="right">End Date :</td> <td><asp:TextBox id="dtEndDate" runat="server" onTextChanged="set_Duration" autopostback="true" cssClass="mandatory"/></td> <td><asp:CompareValidator id="vdEndDate" runat="server" cssClass="ErrorMessage" ControlToValidate="dtEndDate" Type="Date" Operator="DataTypeCheck" ErrorMessage="Incorrect date format"/> </td></tr>
As you can see when the user changes the text in dtEndDate, i want some code to fire. However I only want this code to fire if they have entered a correct date format, tested by vdEndDate, my validator control. So in my script to fire I have this:
public void set_Duration(Object sender, EventArgs e) { if (vdEndDate.IsValid) { blah blah } }
But when i put in a silly date and exit the field, the code still fires and errors coz my date format is wrong for the code i've written. Why is it not escaping the if condition?? I even see the validator control error message pop up briefly before it bombs. So surely vdEndDate is not valid when it enters my code????
I think you meant sender not the eventargs parameter ??? might be wrong.
But no it doesnt like that anyway.
It says in my ASP.NET book you can check to see if individual controls are
valid by
[validatorcontrolid].IsValid
Why does it bypass the if statement ?!
"Dan Bass" wrote: Should that not be
if ( e.IsValid ) { //.... }
instead of vdEndDate?
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in message news:E1**********************************@microsof t.com... Hi, I have a text box with corresponding comparevalidator as so..
<tr><td align="right">End Date :</td> <td><asp:TextBox id="dtEndDate" runat="server" onTextChanged="set_Duration" autopostback="true" cssClass="mandatory"/></td> <td><asp:CompareValidator id="vdEndDate" runat="server" cssClass="ErrorMessage" ControlToValidate="dtEndDate" Type="Date" Operator="DataTypeCheck" ErrorMessage="Incorrect date format"/> </td></tr>
As you can see when the user changes the text in dtEndDate, i want some code to fire. However I only want this code to fire if they have entered a correct date format, tested by vdEndDate, my validator control. So in my script to fire I have this:
public void set_Duration(Object sender, EventArgs e) { if (vdEndDate.IsValid) { blah blah } }
But when i put in a silly date and exit the field, the code still fires and errors coz my date format is wrong for the code i've written. Why is it not escaping the if condition?? I even see the validator control error message pop up briefly before it bombs. So surely vdEndDate is not valid when it enters my code????
The easiest way to debug javascript is to litter it with alerts...
put an alert just into your function to check it's firing, then an alert
(vdEndDate) to check it's a valid object, then alert (vdEndDate.IsValid),
etc... this'll help you narrow down which parameter is causing the problems.
Javascript just stops executing if there's an error, which can be annoying,
so another option is try/catch while also using alerts to check where your
functions running too...
Good luck.
Dan.
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:9A**********************************@microsof t.com... I think you meant sender not the eventargs parameter ??? might be wrong.
But no it doesnt like that anyway.
It says in my ASP.NET book you can check to see if individual controls are valid by
[validatorcontrolid].IsValid
Why does it bypass the if statement ?!
"Dan Bass" wrote:
Should that not be
if ( e.IsValid ) { //.... }
instead of vdEndDate?
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in message news:E1**********************************@microsof t.com... > Hi, I have a text box with corresponding comparevalidator as so.. > > <tr><td align="right">End Date :</td> > <td><asp:TextBox id="dtEndDate" runat="server" > onTextChanged="set_Duration" > autopostback="true" cssClass="mandatory"/></td> > <td><asp:CompareValidator id="vdEndDate" runat="server" > cssClass="ErrorMessage" ControlToValidate="dtEndDate" Type="Date" > Operator="DataTypeCheck" ErrorMessage="Incorrect date format"/> > </td></tr> > > As you can see when the user changes the text in dtEndDate, i want some > code > to fire. However I only want this code to fire if they have entered a > correct > date format, tested by vdEndDate, my validator control. So in my script > to > fire I have this: > > public void set_Duration(Object sender, EventArgs e) { > if (vdEndDate.IsValid) { > blah blah > } > } > > But when i put in a silly date and exit the field, the code still fires > and > errors coz my date format is wrong for the code i've written. Why is it > not > escaping the if condition?? I even see the validator control error > message > pop up briefly before it bombs. So surely vdEndDate is not valid when > it > enters my code????
i'm not writing javascript its C# on the server side checking if the web
control is valid!
"Dan Bass" wrote: The easiest way to debug javascript is to litter it with alerts...
put an alert just into your function to check it's firing, then an alert (vdEndDate) to check it's a valid object, then alert (vdEndDate.IsValid), etc... this'll help you narrow down which parameter is causing the problems.
Javascript just stops executing if there's an error, which can be annoying, so another option is try/catch while also using alerts to check where your functions running too...
Good luck.
Dan.
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in message news:9A**********************************@microsof t.com...I think you meant sender not the eventargs parameter ??? might be wrong.
But no it doesnt like that anyway.
It says in my ASP.NET book you can check to see if individual controls are valid by
[validatorcontrolid].IsValid
Why does it bypass the if statement ?!
"Dan Bass" wrote:
Should that not be
if ( e.IsValid ) { //.... }
instead of vdEndDate?
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in message news:E1**********************************@microsof t.com... > Hi, I have a text box with corresponding comparevalidator as so.. > > <tr><td align="right">End Date :</td> > <td><asp:TextBox id="dtEndDate" runat="server" > onTextChanged="set_Duration" > autopostback="true" cssClass="mandatory"/></td> > <td><asp:CompareValidator id="vdEndDate" runat="server" > cssClass="ErrorMessage" ControlToValidate="dtEndDate" Type="Date" > Operator="DataTypeCheck" ErrorMessage="Incorrect date format"/> > </td></tr> > > As you can see when the user changes the text in dtEndDate, i want some > code > to fire. However I only want this code to fire if they have entered a > correct > date format, tested by vdEndDate, my validator control. So in my script > to > fire I have this: > > public void set_Duration(Object sender, EventArgs e) { > if (vdEndDate.IsValid) { > blah blah > } > } > > But when i put in a silly date and exit the field, the code still fires > and > errors coz my date format is wrong for the code i've written. Why is it > not > escaping the if condition?? I even see the validator control error > message > pop up briefly before it bombs. So surely vdEndDate is not valid when > it > enters my code????
On the server side, there is an order of execution.
Page_Load
TextChanged
OnClick
PreRender
Validation automatically fires during the OnClick event, due to the Button
control calling Page.Validate() for you. Prior to this point, all validators
are at their default state of IsValid=true.
In your TextChange method, simply do this:
vdEndDate.Validate();
if (vdEndDate.IsValid) ....
--- Peter Blum www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at http://www.peterblum.com/vam/home.aspx
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in
message news:E1**********************************@microsof t.com... Hi, I have a text box with corresponding comparevalidator as so..
<tr><td align="right">End Date :</td> <td><asp:TextBox id="dtEndDate" runat="server" onTextChanged="set_Duration" autopostback="true" cssClass="mandatory"/></td> <td><asp:CompareValidator id="vdEndDate" runat="server" cssClass="ErrorMessage" ControlToValidate="dtEndDate" Type="Date" Operator="DataTypeCheck" ErrorMessage="Incorrect date format"/> </td></tr>
As you can see when the user changes the text in dtEndDate, i want some code to fire. However I only want this code to fire if they have entered a correct date format, tested by vdEndDate, my validator control. So in my script to fire I have this:
public void set_Duration(Object sender, EventArgs e) { if (vdEndDate.IsValid) { blah blah } }
But when i put in a silly date and exit the field, the code still fires and errors coz my date format is wrong for the code i've written. Why is it not escaping the if condition?? I even see the validator control error message pop up briefly before it bombs. So surely vdEndDate is not valid when it enters my code????
i see. Very helpful to give me the order of exec, thanks so much.
On the same vein, I have been also getting a javascript error
Page..Validators.isvalid is null or not an object (something like that I'm at
home now) I wondered if this solution will solve that? I have had to disable
client scripts just to avoid it, obviously not ideal. Ring any bells ??
"Peter Blum" wrote: On the server side, there is an order of execution. Page_Load TextChanged OnClick PreRender
Validation automatically fires during the OnClick event, due to the Button control calling Page.Validate() for you. Prior to this point, all validators are at their default state of IsValid=true.
In your TextChange method, simply do this: vdEndDate.Validate(); if (vdEndDate.IsValid) ....
--- Peter Blum www.PeterBlum.com Email: PL****@PeterBlum.com Creator of "Professional Validation And More" at http://www.peterblum.com/vam/home.aspx
"louise raisbeck" <lo************@discussions.microsoft.com> wrote in message news:E1**********************************@microsof t.com... Hi, I have a text box with corresponding comparevalidator as so..
<tr><td align="right">End Date :</td> <td><asp:TextBox id="dtEndDate" runat="server" onTextChanged="set_Duration" autopostback="true" cssClass="mandatory"/></td> <td><asp:CompareValidator id="vdEndDate" runat="server" cssClass="ErrorMessage" ControlToValidate="dtEndDate" Type="Date" Operator="DataTypeCheck" ErrorMessage="Incorrect date format"/> </td></tr>
As you can see when the user changes the text in dtEndDate, i want some code to fire. However I only want this code to fire if they have entered a correct date format, tested by vdEndDate, my validator control. So in my script to fire I have this:
public void set_Duration(Object sender, EventArgs e) { if (vdEndDate.IsValid) { blah blah } }
But when i put in a silly date and exit the field, the code still fires and errors coz my date format is wrong for the code i've written. Why is it not escaping the if condition?? I even see the validator control error message pop up briefly before it bombs. So surely vdEndDate is not valid when it enters my code???? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John Roth |
last post by:
I'm adding a thread for comments on Gerrit Holl's pre-pep, which
can be found here:
http://tinyurl.com/2578q
Frankly, I like the idea. It's about time that all of the file
and directory stuff...
|
by: Paul Tomlinson |
last post by:
The keyword new is required on 'B.IsValid' because it hides inherited member
'A.IsValid'
All I have a couple of classes which resemble (sort of!) this:
public class A
{
public bool bIsValid =...
|
by: Mike P |
last post by:
I have a form with a Serial No and Pin text box which are validated with
required field validators. Once they are validated my code goes to a
btn_Click event and if Page.IsValid then checks to see...
|
by: Jon Davis |
last post by:
This is always returning True, even when fields are empty. Why?
private bool ValidatePageOne() {
bool ret = true;
foreach (Control ctrl in PageOnePanel.Controls) {
if...
|
by: Mike Chen |
last post by:
We know in server code, we can check the page validated by using
Page.IsValid where we put some validator controls on aspx page.
I want to set some value after validating user input values on...
| |
by: dean_wilson |
last post by:
Hello,
I am using a regular expression validator for a textbox where
numerics should only be entered.
The error message appears when non numerics are entered, as it
should. After clicking the...
|
by: pyramid |
last post by:
I am new to C++, and one of the homework we have pertains to Functions. The problem is:
Write a function called isValid that determines whether any 3 values can represent the sides of a...
|
by: Andrew Jocelyn |
last post by:
Hi
I have couple of dropdown controls each with a requiredfieldvalidator. I
clear the dropdownlist in the button click event. When the page is rendered
the dropdown validator already flags it's...
|
by: =?Utf-8?B?R2FyeSBMYXJpbWVy?= |
last post by:
I an asp.net web page with a simple form and a Submit button. Form entries
are validated client side, but as a back up I would also like to validate
server side, but not sure where to do it code....
|
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,...
|
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...
| |
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |