Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > isvalid not working for a text box

Reply
Thread Tools

isvalid not working for a text box

 
 
=?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
Guest
Posts: n/a
 
      11-23-2004
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????
 
Reply With Quote
 
 
 
 
Dan Bass
Guest
Posts: n/a
 
      11-23-2004
Should that not be

if ( e.IsValid )
{
//....
}

instead of vdEndDate?

"louise raisbeck" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> 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????



 
Reply With Quote
 
 
 
 
=?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
Guest
Posts: n/a
 
      11-23-2004
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" <(E-Mail Removed)> wrote in
> message news:(E-Mail Removed)...
> > 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????

>
>
>

 
Reply With Quote
 
Dan Bass
Guest
Posts: n/a
 
      11-23-2004
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" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
>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" <(E-Mail Removed)> wrote in
>> message news:(E-Mail Removed)...
>> > 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????

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
Guest
Posts: n/a
 
      11-23-2004
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" <(E-Mail Removed)> wrote in
> message news:(E-Mail Removed)...
> >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" <(E-Mail Removed)> wrote in
> >> message news:(E-Mail Removed)...
> >> > 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????
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Peter Blum
Guest
Posts: n/a
 
      11-23-2004
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: http://www.velocityreviews.com/forums/(E-Mail Removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"louise raisbeck" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> 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????



 
Reply With Quote
 
=?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
Guest
Posts: n/a
 
      11-23-2004
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: (E-Mail Removed)
> Creator of "Professional Validation And More" at
> http://www.peterblum.com/vam/home.aspx
>
> "louise raisbeck" <(E-Mail Removed)> wrote in
> message news:(E-Mail Removed)...
> > 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????

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
div box questions; float text around a box, fit box to image size Gnarlodious HTML 4 05-05-2010 11:30 AM
Page.IsValid Not Working dean_wilson@teamji.com ASP .Net 5 07-16-2007 05:42 AM
Page.IsValid behavior Drunken Coder ASP .Net 5 01-09-2004 05:08 PM
automatically calling custom isValid() function DesignerX ASP .Net 1 12-18-2003 04:35 AM
Page.IsValid Mike P ASP .Net 0 06-25-2003 09:18 AM



Advertisments