473,387 Members | 1,528 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,387 software developers and data experts.

Custom Validator validates, but doesn't tell

Hi. I have an ASP control on my page:

<asp:Calendar
ID="calStart"
................ Etc
</asp:Calendar>

and I have a Custom Validator defined as

<asp:CustomValidator
id="validDate"
Text="*"
ErrorMessage= "The date of the meeting should be at least 7 business
days later than the day of the request !"
Display="Dynamic"
OnServerValidate="ServerValidate" runat="server">
</asp:CustomValidator>

and ServerValidate is defined as:

Protected Sub ServerValidate(ByVal source As Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs)

Dim objCustomValidator As CustomValidator
Dim objValidationSummary As ValidationSummary
Dim dtChosenDate As Date

objCustomValidator = CType(source, CustomValidator)
objValidationSummary = CType(Me.FindControl("validSummary"),
ValidationSummary)
dtChosenDate =
CType(objCustomValidator.Parent.FindControl("calSt art"),
Calendar).SelectedDate

'The date must be greater than today by 7 business days:
If DateDiff(DateInterval.Day, Now, dtChosenDate) < 9 Then
args.IsValid = False
objCustomValidator.IsValid = False
Else
args.IsValid = True
End If

objValidationSummary.Controls.Add(objCustomValidat or)

objValidationSummary = Nothing
objCustomValidator = Nothing
End Sub

I also have a ValidationSummary control:
<asp:ValidationSummary
ID="validSummary"
CssClass="MyTextBox"
ShowSummary="false"
ShowMessageBox="true"
DisplayMode="BulletList"
HeaderText="The following data is wrong or missing:"
runat="server"
/>

The validation control works fine with all the others validators on
this page, except this CustomValidator: when I try to leave the page,
if the date is not greater than today by 9, it won't allow me to leave
the page (meaning it's working), but it does not register with the
ValidationSummary control. Where is my problem ?

On a side note - two more questions:
1. When I reset the page (after navigating back and forth), I say in
Page_Load
calStart.SelectedDate = ..... (valid date)
but nothing shows on the screen !
2. can I stop the calendar control from posting back ? Do I have to
write my own javascript-based calendar ?

Thank you very much.
Alex. Nitulescu

Apr 4 '07 #1
8 3891
Wow! I think you have made this way more difficult than it needs to be.

- First, why aren't you doing this validation on the client (and then as a
backup measure on the server)?

- Second, why are you making new instances of controls that you already have
and can access on the server simply by using their id?

- Third, why are you accessing existing controls (and then casting them back
to their own type) via some other control, rather than directly?

- Fourth, why doesn't your code have a "Handles" clause on the event handler
declaration line (in other words, why do you have AutoEventWireUp set to
true)?

- Fifth, why are you setting your object references to Nothing? That's so
VB 6.0 and not necessary in VB.NET.

- Sixth, since calendar controls can't be validated, why not just put a
label on the page somewhere with an appropriate error message in it, but
make it hidden?

Here's how I think your server code should read (but I still think you
should add client-side validation as well to reduce server trips). This
code assumes you have placed a label control somewhere on your page and
called it "lblCalendarMessage". In addition, this label should have its
visible property set to False by default:

Protected Sub ServerValidate(ByVal source As Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs)

'The date must be greater than today by 7 business days:
If calStart.selectedDate < Today.AddDays(9) Then
args.IsValid = False
lblCalendarMessage.visible = True
Else
args.IsValid = True
lblCalendarMessage.visible = False
End If
End Sub
On a side note - two more questions:
1. When I reset the page (after navigating back and forth), I say in
Page_Load
calStart.SelectedDate = ..... (valid date)
but nothing shows on the screen !
Are you putting this code inside of a Not IsPostBack check?
2. can I stop the calendar control from posting back ? Do I have to
write my own javascript-based calendar ?
All web form controls are server controls and, as such, they postback. If
you don't want this, then yes, you must come up with your own client side
calendar.
Apr 4 '07 #2
Scott, thank you very much for your answer.

1. You're right, I don't need the extra objects.
2. All the other objects on this page register with the
ValidationSummary, so if I show that label, this would be an exception
to the "rule of the page", and will be annoying.
3. I could do it on the client, and I should, I know, but I don't know
enough JScript to make it work. I could find the
calendar object, but then I could not finish the rest of the function
properly - I know I need to compare the dates in JavaScript and then
set args.IsValid to false. I will try to do that. OTOH, I think that I
need to write this function to make the validation summary work - it
might be that it does not show THIS message simply because my
CustomValidator control only has a server function, not a client one
as well.... I'm not sure of this, though.
4. I have AutoEventWireup="false", but I also have
OnServerValidate="ServerValidate" for the CustomValidator object, so I
think that Handles will not help in any way.
5. For the suppl. question #1 - yes, and the code passes thru there -
no errors, but it simply doesn't change anything - the calendar looks
the same, that date is NOT selected - the user has to select it again,
although all the other (many) controls on this page have retrieved
their values when the user navigates back and forth thru the pages of
the site (my web-site works as a 'Wizard', i.e. Step 1/9, Next, Step
2/9, Next, Step 3/9, etc, and Step 9/9=Commit, the last one. Until
here, all settings made in pages 1....8 can still be changed. This
page, with the calendar, is Step 8/9).

Thanks again, Scott, for reading this.
Alex.
On Apr 4, 1:48 pm, "Scott M." <s...@nospam.nospamwrote:
Wow! I think you have made this way more difficult than it needs to be.

- First, why aren't you doing this validation on the client (and then as a
backup measure on the server)?

- Second, why are you making new instances of controls that you already have
and can access on the server simply by using their id?

- Third, why are you accessing existing controls (and then casting them back
to their own type) via some other control, rather than directly?

- Fourth, why doesn't your code have a "Handles" clause on the event handler
declaration line (in other words, why do you have AutoEventWireUp set to
true)?

- Fifth, why are you setting your object references to Nothing? That's so
VB 6.0 and not necessary in VB.NET.

- Sixth, since calendar controls can't be validated, why not just put a
label on the page somewhere with an appropriate error message in it, but
make it hidden?

Here's how I think your server code should read (but I still think you
should add client-side validation as well to reduce server trips). This
code assumes you have placed a label control somewhere on your page and
called it "lblCalendarMessage". In addition, this label should have its
visible property set to False by default:

Protected Sub ServerValidate(ByVal source As Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs)

'The date must be greater than today by 7 business days:
If calStart.selectedDate < Today.AddDays(9) Then
args.IsValid = False
lblCalendarMessage.visible = True
Else
args.IsValid = True
lblCalendarMessage.visible = False
End If
End Sub
On a side note - two more questions:
1. When I reset the page (after navigating back and forth), I say in
Page_Load
calStart.SelectedDate = ..... (valid date)
but nothing shows on the screen !

Are you putting this code inside of a Not IsPostBack check?
2. can I stop the calendar control from posting back ? Do I have to
write my own javascript-based calendar ?

All web form controls are server controls and, as such, they postback. If
you don't want this, then yes, you must come up with your own client side
calendar.

Apr 4 '07 #3
See my comments inline:
"Radu" <cu*************@yahoo.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
Scott, thank you very much for your answer.

1. You're right, I don't need the extra objects.
2. All the other objects on this page register with the
ValidationSummary, so if I show that label, this would be an exception
to the "rule of the page", and will be annoying.
I don't know what "rule of the page" you are referring to. You already have
an exception, in that Calendar controls can't be validated directly, so the
label idea is the simplest solution. Just put the label next to your
validation summary and format the text the same way the validation summary's
text is formatted - problem solved.
3. I could do it on the client, and I should, I know, but I don't know
enough JScript to make it work. I could find the
calendar object, but then I could not finish the rest of the function
properly - I know I need to compare the dates in JavaScript and then
set args.IsValid to false. I will try to do that. OTOH, I think that I
need to write this function to make the validation summary work - it
might be that it does not show THIS message simply because my
CustomValidator control only has a server function, not a client one
as well.... I'm not sure of this, though.
4. I have AutoEventWireup="false", but I also have
OnServerValidate="ServerValidate" for the CustomValidator object, so I
think that Handles will not help in any way.
OnServerValidate has nothing to do with AutoEventWireUp. AutoEventWireUp
being false (which is what you have and what you should have) means that
event handlers (your Sub ServerValidate) will be called based on the
"Handles" clause on the event handler declaration. You don't have one, so
how and why would this Sub ever get called? AutoEventWireUp being set to
True (which is not the way you should set it) means that event handlers are
automatically called based on the name of the procedure (as in the old VB
6.0 world). In the old days event handlers had to be a combination of the
control name, an underscore and the event to handle (Button1_Click()). The
bottom line here is that you have AutoEventWireUp set correctly, but you
don't have a Handles clause. How did you create this event handler? Did
you type it in yourself or did you double-click on the validation control
and let VS .NET create the server-side event handler declaration for you
(the best way)?
5. For the suppl. question #1 - yes, and the code passes thru there -
no errors, but it simply doesn't change anything - the calendar looks
the same, that date is NOT selected - the user has to select it again,
although all the other (many) controls on this page have retrieved
their values when the user navigates back and forth thru the pages of
the site (my web-site works as a 'Wizard', i.e. Step 1/9, Next, Step
2/9, Next, Step 3/9, etc, and Step 9/9=Commit, the last one. Until
here, all settings made in pages 1....8 can still be changed. This
page, with the calendar, is Step 8/9).
This may have to do with ViewState and/or not placing your code inside of an
If Not IsPostBack Then statement inside of Page_Load.
>
Thanks again, Scott, for reading this.
Alex.
On Apr 4, 1:48 pm, "Scott M." <s...@nospam.nospamwrote:
>Wow! I think you have made this way more difficult than it needs to be.

- First, why aren't you doing this validation on the client (and then as
a
backup measure on the server)?

- Second, why are you making new instances of controls that you already
have
and can access on the server simply by using their id?

- Third, why are you accessing existing controls (and then casting them
back
to their own type) via some other control, rather than directly?

- Fourth, why doesn't your code have a "Handles" clause on the event
handler
declaration line (in other words, why do you have AutoEventWireUp set to
true)?

- Fifth, why are you setting your object references to Nothing? That's
so
VB 6.0 and not necessary in VB.NET.

- Sixth, since calendar controls can't be validated, why not just put a
label on the page somewhere with an appropriate error message in it, but
make it hidden?

Here's how I think your server code should read (but I still think you
should add client-side validation as well to reduce server trips). This
code assumes you have placed a label control somewhere on your page and
called it "lblCalendarMessage". In addition, this label should have its
visible property set to False by default:

Protected Sub ServerValidate(ByVal source As Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs )

'The date must be greater than today by 7 business days:
If calStart.selectedDate < Today.AddDays(9) Then
args.IsValid = False
lblCalendarMessage.visible = True
Else
args.IsValid = True
lblCalendarMessage.visible = False
End If
End Sub
On a side note - two more questions:
1. When I reset the page (after navigating back and forth), I say in
Page_Load
calStart.SelectedDate = ..... (valid date)
but nothing shows on the screen !

Are you putting this code inside of a Not IsPostBack check?
2. can I stop the calendar control from posting back ? Do I have to
write my own javascript-based calendar ?

All web form controls are server controls and, as such, they postback. If
you don't want this, then yes, you must come up with your own client side
calendar.


Apr 4 '07 #4
not sure what you are trying to do. a validator has two properties,

Text = dynamic message to display when validation fails
ErrorText - message to display in summary when validation fails

not sure why you are adding your control to the summary, why you are not
using ControlToValidate.

-- bruce (sqlwork.com)
Radu wrote:
Hi. I have an ASP control on my page:

<asp:Calendar
ID="calStart"
............... Etc
</asp:Calendar>

and I have a Custom Validator defined as

<asp:CustomValidator
id="validDate"
Text="*"
ErrorMessage= "The date of the meeting should be at least 7 business
days later than the day of the request !"
Display="Dynamic"
OnServerValidate="ServerValidate" runat="server">
</asp:CustomValidator>

and ServerValidate is defined as:

Protected Sub ServerValidate(ByVal source As Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs)

Dim objCustomValidator As CustomValidator
Dim objValidationSummary As ValidationSummary
Dim dtChosenDate As Date

objCustomValidator = CType(source, CustomValidator)
objValidationSummary = CType(Me.FindControl("validSummary"),
ValidationSummary)
dtChosenDate =
CType(objCustomValidator.Parent.FindControl("calSt art"),
Calendar).SelectedDate

'The date must be greater than today by 7 business days:
If DateDiff(DateInterval.Day, Now, dtChosenDate) < 9 Then
args.IsValid = False
objCustomValidator.IsValid = False
Else
args.IsValid = True
End If

objValidationSummary.Controls.Add(objCustomValidat or)

objValidationSummary = Nothing
objCustomValidator = Nothing
End Sub

I also have a ValidationSummary control:
<asp:ValidationSummary
ID="validSummary"
CssClass="MyTextBox"
ShowSummary="false"
ShowMessageBox="true"
DisplayMode="BulletList"
HeaderText="The following data is wrong or missing:"
runat="server"
/>

The validation control works fine with all the others validators on
this page, except this CustomValidator: when I try to leave the page,
if the date is not greater than today by 9, it won't allow me to leave
the page (meaning it's working), but it does not register with the
ValidationSummary control. Where is my problem ?

On a side note - two more questions:
1. When I reset the page (after navigating back and forth), I say in
Page_Load
calStart.SelectedDate = ..... (valid date)
but nothing shows on the screen !
2. can I stop the calendar control from posting back ? Do I have to
write my own javascript-based calendar ?

Thank you very much.
Alex. Nitulescu
Apr 4 '07 #5
Inline....

"bruce barker" <no****@nospam.comwrote in message
news:uy**************@TK2MSFTNGP03.phx.gbl...
not sure what you are trying to do. a validator has two properties,

Text = dynamic message to display when validation fails
ErrorText - message to display in summary when validation fails

not sure why you are adding your control to the summary, why you are not
using ControlToValidate.
Because Calendar controls can't be validated. If you try to set the
ControlToValidate property of a validator to a calendar control, you will
get a compilie error.
>
-- bruce (sqlwork.com)
Radu wrote:
>Hi. I have an ASP control on my page:

<asp:Calendar
ID="calStart"
............... Etc
</asp:Calendar>

and I have a Custom Validator defined as

<asp:CustomValidator
id="validDate"
Text="*"
ErrorMessage= "The date of the meeting should be at least 7 business
days later than the day of the request !"
Display="Dynamic"
OnServerValidate="ServerValidate" runat="server">
</asp:CustomValidator>

and ServerValidate is defined as:

Protected Sub ServerValidate(ByVal source As Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs )

Dim objCustomValidator As CustomValidator
Dim objValidationSummary As ValidationSummary
Dim dtChosenDate As Date

objCustomValidator = CType(source, CustomValidator)
objValidationSummary = CType(Me.FindControl("validSummary"),
ValidationSummary)
dtChosenDate =
CType(objCustomValidator.Parent.FindControl("calS tart"),
Calendar).SelectedDate

'The date must be greater than today by 7 business days:
If DateDiff(DateInterval.Day, Now, dtChosenDate) < 9 Then
args.IsValid = False
objCustomValidator.IsValid = False
Else
args.IsValid = True
End If

objValidationSummary.Controls.Add(objCustomValida tor)

objValidationSummary = Nothing
objCustomValidator = Nothing
End Sub

I also have a ValidationSummary control:
<asp:ValidationSummary
ID="validSummary"
CssClass="MyTextBox"
ShowSummary="false"
ShowMessageBox="true"
DisplayMode="BulletList"
HeaderText="The following data is wrong or missing:"
runat="server"
/>

The validation control works fine with all the others validators on
this page, except this CustomValidator: when I try to leave the page,
if the date is not greater than today by 9, it won't allow me to leave
the page (meaning it's working), but it does not register with the
ValidationSummary control. Where is my problem ?

On a side note - two more questions:
1. When I reset the page (after navigating back and forth), I say in
Page_Load
calStart.SelectedDate = ..... (valid date)
but nothing shows on the screen !
2. can I stop the calendar control from posting back ? Do I have to
write my own javascript-based calendar ?

Thank you very much.
Alex. Nitulescu

Apr 4 '07 #6
Scott, my comments are inline. Thanks.
2. All the other objects on this page register with the
ValidationSummary, so if I show that label, this would be an exception
to the "rule of the page", and will be annoying.

I don't know what "rule of the page" you are referring to. You already have
an exception, in that Calendar controls can't be validated directly, so the
label idea is the simplest solution. Just put the label next to your
validation summary and format the text the same way the validation summary's
text is formatted - problem solved.
The "rule of the page" (and of the web-site, I might add) being that
all problems with the data are shown in a message-box, and therefore
this calendar control would be the only one which would show its error
text in a label. So you'll have (maybe at the same time) a label on
the side of the calendar saying "The value selected has to be....",
and a message box saying "Data....xxx... has to be numeric".
4. I have AutoEventWireup="false", but I also have
OnServerValidate="ServerValidate" for the CustomValidator object, so I
think that Handles will not help in any way.
OnServerValidate has nothing to do with AutoEventWireUp. AutoEventWireUp
being false (which is what you have and what you should have) means that
event handlers (your Sub ServerValidate) will be called based on the
"Handles" clause on the event handler declaration. You don't have one, so
how and why would this Sub ever get called? AutoEventWireUp being set to
True (which is not the way you should set it) means that event handlers are
automatically called based on the name of the procedure (as in the old VB
6.0 world). In the old days event handlers had to be a combination of the
control name, an underscore and the event to handle (Button1_Click()). The
bottom line here is that you have AutoEventWireUp set correctly, but you
don't have a Handles clause. How did you create this event handler? Did
you type it in yourself or did you double-click on the validation control
and let VS .NET create the server-side event handler declaration for you
(the best way)?
How did I create it ? I simply started a new function, with its name
as specified in "OnServerValidate". Yes, you'll add, then why does it
execute without the Handles clause ? And still, it executes just the
same - I guess that mentioning its name in OnServerValidate is enough.
The code *PASSES* through there, guaranteed :-))))
5. For the suppl. question #1 - yes, and the code passes thru there -
no errors, but it simply doesn't change anything - the calendar looks
the same, that date is NOT selected - the user has to select it again,
although all the other (many) controls on this page have retrieved
their values when the user navigates back and forth thru the pages of
the site (my web-site works as a 'Wizard', i.e. Step 1/9, Next, Step
2/9, Next, Step 3/9, etc, and Step 9/9=Commit, the last one. Until
here, all settings made in pages 1....8 can still be changed. This
page, with the calendar, is Step 8/9).

This may have to do with ViewState and/or not placing your code inside of an
If Not IsPostBack Then statement inside of Page_Load.
Yet..... the code passes through there - all my other controls are
properly re-initiated. I took it step-by-step, and the instruction
executes, but nothing happens :-(((

Thank you for answering.
Alex.

Apr 5 '07 #7
A couple of last thoughts, inline...
"Radu" <cu*************@yahoo.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
Scott, my comments are inline. Thanks.
2. All the other objects on this page register with the
ValidationSummary, so if I show that label, this would be an exception
to the "rule of the page", and will be annoying.

I don't know what "rule of the page" you are referring to. You already
have
an exception, in that Calendar controls can't be validated directly, so
the
label idea is the simplest solution. Just put the label next to your
validation summary and format the text the same way the validation
summary's
text is formatted - problem solved.

The "rule of the page" (and of the web-site, I might add) being that
all problems with the data are shown in a message-box, and therefore
this calendar control would be the only one which would show its error
text in a label. So you'll have (maybe at the same time) a label on
the side of the calendar saying "The value selected has to be....",
and a message box saying "Data....xxx... has to be numeric".
Ok, no problem, don't use a label. Instead simply pass some client-side
JavaScript to the client from the server and have that script make an alert
with your error message, as in:

response.write("<SCRIPT TYPE='text/JavaScript'>alert('You must pick a date
at least 5 business days in the future.')</SCRIPT>")

My point is that this problem is more easily solved without trying to tap
into the validatorsummary control and making your server-side code much more
compicated.

4. I have AutoEventWireup="false", but I also have
OnServerValidate="ServerValidate" for the CustomValidator object, so I
think that Handles will not help in any way.
>OnServerValidate has nothing to do with AutoEventWireUp. AutoEventWireUp
being false (which is what you have and what you should have) means that
event handlers (your Sub ServerValidate) will be called based on the
"Handles" clause on the event handler declaration. You don't have one,
so
how and why would this Sub ever get called? AutoEventWireUp being set to
True (which is not the way you should set it) means that event handlers
are
automatically called based on the name of the procedure (as in the old VB
6.0 world). In the old days event handlers had to be a combination of
the
control name, an underscore and the event to handle (Button1_Click()).
The
bottom line here is that you have AutoEventWireUp set correctly, but you
don't have a Handles clause. How did you create this event handler? Did
you type it in yourself or did you double-click on the validation control
and let VS .NET create the server-side event handler declaration for you
(the best way)?

How did I create it ? I simply started a new function, with its name
as specified in "OnServerValidate". Yes, you'll add, then why does it
execute without the Handles clause ? And still, it executes just the
same - I guess that mentioning its name in OnServerValidate is enough.
The code *PASSES* through there, guaranteed :-))))
If you are using VS .NET, you should NEVER create the "shell" of an event
handler manually - this is a leading cause of errors. Instead, just
double-click on the control you wish to write server-side code for and let
VS.NET create the event handler for you. Even though you state that this
code is being called, I strongly reccomend you do this and copy the "guts"
of your existing procedure into the new one created by VS .NET and then
delete the empty old one.
5. For the suppl. question #1 - yes, and the code passes thru there -
no errors, but it simply doesn't change anything - the calendar looks
the same, that date is NOT selected - the user has to select it again,
although all the other (many) controls on this page have retrieved
their values when the user navigates back and forth thru the pages of
the site (my web-site works as a 'Wizard', i.e. Step 1/9, Next, Step
2/9, Next, Step 3/9, etc, and Step 9/9=Commit, the last one. Until
here, all settings made in pages 1....8 can still be changed. This
page, with the calendar, is Step 8/9).

This may have to do with ViewState and/or not placing your code inside of
an
If Not IsPostBack Then statement inside of Page_Load.

Yet..... the code passes through there - all my other controls are
properly re-initiated. I took it step-by-step, and the instruction
executes, but nothing happens :-(((
But (for the third time), do you have your code written inside of a If Not
IsPostBack Then statement? The fact that the code passes through Page_Load
doesn't mean much (all pages process this event), but you only want the date
to change on a PostBack, right?
>
Thank you for answering.
Alex.

Apr 5 '07 #8
Wow, Scott, great idea, I put

Response.Write("<SCRIPT TYPE='text/JavaScript'>alert('A minimum of 7
business days from the request date is required in order to process
your demand.\nPlease pick a date at least 7 business days in the
future.')</SCRIPT>")

it in and, voila, it works. It's not acting exactly like the other
controls on the page, but at least it works !

Thanks a lot :-)
Alex

PS. Yes, sorry, it *was* inside a "If Not Page.IsPostBack Then" block.

On Apr 5, 10:29 am, "Scott M." <s...@nospam.nospamwrote:
A couple of last thoughts, inline...

"Radu" <cuca_macaii2...@yahoo.comwrote in message

news:11**********************@l77g2000hsb.googlegr oups.com...


Scott, my comments are inline. Thanks.
2. All the other objects on this page register with the
ValidationSummary, so if I show that label, this would be an exception
to the "rule of the page", and will be annoying.
I don't know what "rule of the page" you are referring to. You already
have
an exception, in that Calendar controls can't be validated directly, so
the
label idea is the simplest solution. Just put the label next to your
validation summary and format the text the same way the validation
summary's
text is formatted - problem solved.
The "rule of the page" (and of the web-site, I might add) being that
all problems with the data are shown in a message-box, and therefore
this calendar control would be the only one which would show its error
text in a label. So you'll have (maybe at the same time) a label on
the side of the calendar saying "The value selected has to be....",
and a message box saying "Data....xxx... has to be numeric".

Ok, no problem, don't use a label. Instead simply pass some client-side
JavaScript to the client from the server and have that script make an alert
with your error message, as in:

response.write("<SCRIPT TYPE='text/JavaScript'>alert('You must pick a date
at least 5 business days in the future.')</SCRIPT>")

My point is that this problem is more easily solved without trying to tap
into the validatorsummary control and making your server-side code much more
compicated.


4. I have AutoEventWireup="false", but I also have
OnServerValidate="ServerValidate" for the CustomValidator object, so I
think that Handles will not help in any way.
OnServerValidate has nothing to do with AutoEventWireUp. AutoEventWireUp
being false (which is what you have and what you should have) means that
event handlers (your Sub ServerValidate) will be called based on the
"Handles" clause on the event handler declaration. You don't have one,
so
how and why would this Sub ever get called? AutoEventWireUp being set to
True (which is not the way you should set it) means that event handlers
are
automatically called based on the name of the procedure (as in the old VB
6.0 world). In the old days event handlers had to be a combination of
the
control name, an underscore and the event to handle (Button1_Click()).
The
bottom line here is that you have AutoEventWireUp set correctly, but you
don't have a Handles clause. How did you create this event handler? Did
you type it in yourself or did you double-click on the validation control
and let VS .NET create the server-side event handler declaration for you
(the best way)?
How did I create it ? I simply started a new function, with its name
as specified in "OnServerValidate". Yes, you'll add, then why does it
execute without the Handles clause ? And still, it executes just the
same - I guess that mentioning its name in OnServerValidate is enough.
The code *PASSES* through there, guaranteed :-))))

If you are using VS .NET, you should NEVER create the "shell" of an event
handler manually - this is a leading cause of errors. Instead, just
double-click on the control you wish to write server-side code for and let
VS.NET create the event handler for you. Even though you state that this
code is being called, I strongly reccomend you do this and copy the "guts"
of your existing procedure into the new one created by VS .NET and then
delete the empty old one.


5. For the suppl. question #1 - yes, and the code passes thru there -
no errors, but it simply doesn't change anything - the calendar looks
the same, that date is NOT selected - the user has to select it again,
although all the other (many) controls on this page have retrieved
their values when the user navigates back and forth thru the pages of
the site (my web-site works as a 'Wizard', i.e. Step 1/9, Next, Step
2/9, Next, Step 3/9, etc, and Step 9/9=Commit, the last one. Until
here, all settings made in pages 1....8 can still be changed. This
page, with the calendar, is Step 8/9).
This may have to do with ViewState and/or not placing your code inside of
an
If Not IsPostBack Then statement inside of Page_Load.
Yet..... the code passes through there - all my other controls are
properly re-initiated. I took it step-by-step, and the instruction
executes, but nothing happens :-(((

But (for the third time), do you have your code written inside of a If Not
IsPostBack Then statement? The fact that the code passes through Page_Load
doesn't mean much (all pages process this event), but you only want the date
to change on a PostBack, right?


Thank you for answering.
Alex.- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

Apr 9 '07 #9

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

Similar topics

8
by: Spartanicus | last post by:
The document at http://homepage.ntlworld.com/spartanicus/custom_dtd.htm uses a custom DTD, the w3c validator validates it but with this warning: "Unknown Parse Mode! The MIME Media Type...
2
by: Dot net work | last post by:
Hello. If I use an asp.net custom validator control to validate a textbox, what I find is that if I enter in some text that I have already entered and validated in a previous session (you know...
5
by: Mattyw | last post by:
Hi, I'm relatively new to Web Forms, I have been using Required Field Validators and Regular Expression Validators on a Web Form I am developing and everything works as expected using Visual...
9
by: wardy1975 | last post by:
Hi All, Looking for a little expert advice on a few web standards issues. I am currently trying to understand the impact of web standards for a web application I work with. I have been doing a...
40
by: VK | last post by:
Hi, After the response on my request from W3C I'm still unclear about Tidy vs. Validator discrepansies. That started with <IFRAME> issue, but there is more as I know. Anyway, this very basic...
3
by: Arpan | last post by:
Consider the following code which validates a TextBox using RegularExpression: <form id="form1" runat="server"> <asp:TextBox id="txt1" runat="server"/> <asp:RegularExpressionValidator...
6
by: yaru22 | last post by:
I'd like to create a program that validates bunch of urls against the w3c markup validator (http://validator.w3.org/) and store the result in a file. Since I don't know network programming, I...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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.