I have a gridview and have placed customvalidator controls in it.
If I put a break on the sub to do custom validation, run the page, select a
row and press the EDIT button, putting me into Update/Cancel mode, I can edit
the date textbox putting in garbage and press update. It takes the
breakpoint, I step thru, it sets value.isValid=False, and when I exit
routine, same sub fires again (hits same break point) and flow values same
path. Garbage date value still there. If I continue on now, it displays the
gridview, original value of date textbox is back, my error message is not
displayed, but I'm still in Update/Cancel mode,not Edit mode so the update
didn't take place.

<asp:TemplateField HeaderText="Date Stamp"
SortExpression="date_stamp">
<EditItemTemplate>
<asp:CustomValidator ID="Date_Stamp_Update_Validator"
runat="server"
ControlToValidate="Date_Stamp_Update_Txt"
OnServerValidate="Date_Stamp_Update_Txt_Validate"
ValidateEmptyText="true"
Display="Static"
SetFocusOnError="true"
ErrorMessage="Must be YYYY-MM-DD!" ></asp:CustomValidator>
<asp:TextBox ID="Date_Stamp_Update_Txt" runat="server"
Text='<%# Bind("date_stamp") %>'
BorderStyle="Ridge" BackColor="LightYellow"
MaxLength="10" Width="65px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Date_Stamp_Label" runat="server"
Text='<%# Bind("date_stamp") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" VerticalAlign="Bottom" Width="9%"
Wrap="True"/>
<HeaderStyle VerticalAlign="Bottom" />
</asp:TemplateField>


Protected Sub Date_Stamp_Update_Txt_Validate(ByVal sender As Object, ByVal
value As ServerValidateEventArgs)
' Must be YYYY-MM-DD Format:
If value.Value.ToString.Length = 10 Then
Dim dte As DateTime
If DateTime.TryParse(value.Value, dte) Then
value.IsValid = True
Else
value.IsValid = False
End If
Else
value.IsValid = False
End If
End Sub

RE: CustomValidator in GridView getting "no message" on errors by stcheng

stcheng
Fri Mar 14 03:08:43 CDT 2008

Hi dmartin,

From your description, you found that the custom validator in GridView not
work correctly , correct?

I've made a simple test on my side and got a customValidator working (with
server-side validation) in GridView templateField. I've compared the code
and aspx template between my test page and yours. It seems there is no
definte difference. I suggest you try the following things:

** explicitly turn off client-side validation(disable client script)

** Try changing your validation handler in codebehind, use some very simple
code logic to see whether it work.

Here is my test page's aspx and codebehind function for your reference:


=======aspx ....==
.............
<asp:TemplateField HeaderText="name" SortExpression="name">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("name") %>'></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1"
runat="server" ErrorMessage="CustomValidator"
ControlToValidate="TextBox1"
EnableClientScript="False"

onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
=============


===========
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
if (!args.Value.Contains("Name"))
args.IsValid = false;
else args.IsValid = true;

}
=============

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>Thread-Topic: CustomValidator in GridView getting "no message" on errors
>thread-index: AciFTXs6Q1/KAGdKQoegfeOqrsqbfg==
>X-WBNR-Posting-Host: 171.159.64.10
>From: =?Utf-8?B?ZG91Zw==?= <dmartin@newsgroups.nospam>
>Subject: CustomValidator in GridView getting "no message" on errors
>Date: Thu, 13 Mar 2008 14:02:00 -0700

>
>I have a gridview and have placed customvalidator controls in it.
>If I put a break on the sub to do custom validation, run the page, select
a
>row and press the EDIT button, putting me into Update/Cancel mode, I can
edit
>the date textbox putting in garbage and press update. It takes the
>breakpoint, I step thru, it sets value.isValid=False, and when I exit
>routine, same sub fires again (hits same break point) and flow values same
>path. Garbage date value still there. If I continue on now, it displays
the
>gridview, original value of date textbox is back, my error message is not
>displayed, but I'm still in Update/Cancel mode,not Edit mode so the update
>didn't take place.
>
> <asp:TemplateField HeaderText="Date Stamp"
>SortExpression="date_stamp">
> <EditItemTemplate>
> <asp:CustomValidator ID="Date_Stamp_Update_Validator"
>runat="server"
> ControlToValidate="Date_Stamp_Update_Txt"
> OnServerValidate="Date_Stamp_Update_Txt_Validate"
> ValidateEmptyText="true"
> Display="Static"
> SetFocusOnError="true"
> ErrorMessage="Must be YYYY-MM-DD!" ></asp:CustomValidator>
> <asp:TextBox ID="Date_Stamp_Update_Txt"
runat="server"
>Text='<%# Bind("date_stamp") %>'
> BorderStyle="Ridge" BackColor="LightYellow"
> MaxLength="10" Width="65px"></asp:TextBox>
> </EditItemTemplate>
> <ItemTemplate>
> <asp:Label ID="Date_Stamp_Label" runat="server"
>Text='<%# Bind("date_stamp") %>'></asp:Label>
> </ItemTemplate>
> <ItemStyle HorizontalAlign="Left" VerticalAlign="Bottom"
Width="9%"
>Wrap="True"/>
> <HeaderStyle VerticalAlign="Bottom" />
> </asp:TemplateField>
>
>
> Protected Sub Date_Stamp_Update_Txt_Validate(ByVal sender As Object,
ByVal
>value As ServerValidateEventArgs)
> ' Must be YYYY-MM-DD Format:
> If value.Value.ToString.Length = 10 Then
> Dim dte As DateTime
> If DateTime.TryParse(value.Value, dte) Then
> value.IsValid = True
> Else
> value.IsValid = False
> End If
> Else
> value.IsValid = False
> End If
> End Sub
>
>
>


RE: CustomValidator in GridView getting "no message" on errors by dmartin

dmartin
Fri Mar 14 11:22:02 CDT 2008

I added EnableClientScript="false", already had the "onservervalidate=xxx".
This is the routine that is being fired twice, and each time isPostBack is
true, and it fails edit setting isValid="false".

Why is this routine fired twice - seemingly one after the other?

""Steven Cheng"" wrote:

> Hi dmartin,
>
> From your description, you found that the custom validator in GridView not
> work correctly , correct?
>
> I've made a simple test on my side and got a customValidator working (with
> server-side validation) in GridView templateField. I've compared the code
> and aspx template between my test page and yours. It seems there is no
> definte difference. I suggest you try the following things:
>
> ** explicitly turn off client-side validation(disable client script)
>
> ** Try changing your validation handler in codebehind, use some very simple
> code logic to see whether it work.
>
> Here is my test page's aspx and codebehind function for your reference:
>
>
> =======aspx ....==
> ..............
> <asp:TemplateField HeaderText="name" SortExpression="name">
> <EditItemTemplate>
> <asp:TextBox ID="TextBox1" runat="server" Text='<%#
> Bind("name") %>'></asp:TextBox>
> <asp:CustomValidator ID="CustomValidator1"
> runat="server" ErrorMessage="CustomValidator"
> ControlToValidate="TextBox1"
> EnableClientScript="False"
>
> onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
> </EditItemTemplate>
> <ItemTemplate>
> <asp:Label ID="Label1" runat="server" Text='<%#
> Bind("name") %>'></asp:Label>
> </ItemTemplate>
> </asp:TemplateField>
> =============
>
>
> ===========
> protected void CustomValidator1_ServerValidate(object source,
> ServerValidateEventArgs args)
> {
> if (!args.Value.Contains("Name"))
> args.IsValid = false;
> else args.IsValid = true;
>
> }
> =============
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msdnmg@microsoft.com.
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> --------------------
> >Thread-Topic: CustomValidator in GridView getting "no message" on errors
> >thread-index: AciFTXs6Q1/KAGdKQoegfeOqrsqbfg==
> >X-WBNR-Posting-Host: 171.159.64.10
> >From: =?Utf-8?B?ZG91Zw==?= <dmartin@newsgroups.nospam>
> >Subject: CustomValidator in GridView getting "no message" on errors
> >Date: Thu, 13 Mar 2008 14:02:00 -0700
>
> >
> >I have a gridview and have placed customvalidator controls in it.
> >If I put a break on the sub to do custom validation, run the page, select
> a
> >row and press the EDIT button, putting me into Update/Cancel mode, I can
> edit
> >the date textbox putting in garbage and press update. It takes the
> >breakpoint, I step thru, it sets value.isValid=False, and when I exit
> >routine, same sub fires again (hits same break point) and flow values same
> >path. Garbage date value still there. If I continue on now, it displays
> the
> >gridview, original value of date textbox is back, my error message is not
> >displayed, but I'm still in Update/Cancel mode,not Edit mode so the update
> >didn't take place.
> >
> > <asp:TemplateField HeaderText="Date Stamp"
> >SortExpression="date_stamp">
> > <EditItemTemplate>
> > <asp:CustomValidator ID="Date_Stamp_Update_Validator"
> >runat="server"
> > ControlToValidate="Date_Stamp_Update_Txt"
> > OnServerValidate="Date_Stamp_Update_Txt_Validate"
> > ValidateEmptyText="true"
> > Display="Static"
> > SetFocusOnError="true"
> > ErrorMessage="Must be YYYY-MM-DD!" ></asp:CustomValidator>
> > <asp:TextBox ID="Date_Stamp_Update_Txt"
> runat="server"
> >Text='<%# Bind("date_stamp") %>'
> > BorderStyle="Ridge" BackColor="LightYellow"
> > MaxLength="10" Width="65px"></asp:TextBox>
> > </EditItemTemplate>
> > <ItemTemplate>
> > <asp:Label ID="Date_Stamp_Label" runat="server"
> >Text='<%# Bind("date_stamp") %>'></asp:Label>
> > </ItemTemplate>
> > <ItemStyle HorizontalAlign="Left" VerticalAlign="Bottom"
> Width="9%"
> >Wrap="True"/>
> > <HeaderStyle VerticalAlign="Bottom" />
> > </asp:TemplateField>
> >
> >
> > Protected Sub Date_Stamp_Update_Txt_Validate(ByVal sender As Object,
> ByVal
> >value As ServerValidateEventArgs)
> > ' Must be YYYY-MM-DD Format:
> > If value.Value.ToString.Length = 10 Then
> > Dim dte As DateTime
> > If DateTime.TryParse(value.Value, dte) Then
> > value.IsValid = True
> > Else
> > value.IsValid = False
> > End If
> > Else
> > value.IsValid = False
> > End If
> > End Sub
> >
> >
> >
>
>

RE: CustomValidator in GridView getting "no message" on errors by dmartin

dmartin
Fri Mar 14 14:29:00 CDT 2008

I figured it out. I am trying to dynamically modify filtering SQL to add
additional criteria, and added a DataBing to Page_PreRenderComplete - which
isn't working yet, so commenting it out restored errors.

"doug" wrote:

> I added EnableClientScript="false", already had the "onservervalidate=xxx".
> This is the routine that is being fired twice, and each time isPostBack is
> true, and it fails edit setting isValid="false".
>
> Why is this routine fired twice - seemingly one after the other?
>
> ""Steven Cheng"" wrote:
>
> > Hi dmartin,
> >
> > From your description, you found that the custom validator in GridView not
> > work correctly , correct?
> >
> > I've made a simple test on my side and got a customValidator working (with
> > server-side validation) in GridView templateField. I've compared the code
> > and aspx template between my test page and yours. It seems there is no
> > definte difference. I suggest you try the following things:
> >
> > ** explicitly turn off client-side validation(disable client script)
> >
> > ** Try changing your validation handler in codebehind, use some very simple
> > code logic to see whether it work.
> >
> > Here is my test page's aspx and codebehind function for your reference:
> >
> >
> > =======aspx ....==
> > ..............
> > <asp:TemplateField HeaderText="name" SortExpression="name">
> > <EditItemTemplate>
> > <asp:TextBox ID="TextBox1" runat="server" Text='<%#
> > Bind("name") %>'></asp:TextBox>
> > <asp:CustomValidator ID="CustomValidator1"
> > runat="server" ErrorMessage="CustomValidator"
> > ControlToValidate="TextBox1"
> > EnableClientScript="False"
> >
> > onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
> > </EditItemTemplate>
> > <ItemTemplate>
> > <asp:Label ID="Label1" runat="server" Text='<%#
> > Bind("name") %>'></asp:Label>
> > </ItemTemplate>
> > </asp:TemplateField>
> > =============
> >
> >
> > ===========
> > protected void CustomValidator1_ServerValidate(object source,
> > ServerValidateEventArgs args)
> > {
> > if (!args.Value.Contains("Name"))
> > args.IsValid = false;
> > else args.IsValid = true;
> >
> > }
> > =============
> >
> > Sincerely,
> >
> > Steven Cheng
> >
> > Microsoft MSDN Online Support Lead
> >
> >
> > Delighting our customers is our #1 priority. We welcome your comments and
> > suggestions about how we can improve the support we provide to you. Please
> > feel free to let my manager know what you think of the level of service
> > provided. You can send feedback directly to my manager at:
> > msdnmg@microsoft.com.
> >
> > ==================================================
> > Get notification to my posts through email? Please refer to
> > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> > ications.
> >
> > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> > where an initial response from the community or a Microsoft Support
> > Engineer within 1 business day is acceptable. Please note that each follow
> > up response may take approximately 2 business days as the support
> > professional working with you may need further investigation to reach the
> > most efficient resolution. The offering is not appropriate for situations
> > that require urgent, real-time or phone-based interactions or complex
> > project analysis and dump analysis issues. Issues of this nature are best
> > handled working with a dedicated Microsoft Support Engineer by contacting
> > Microsoft Customer Support Services (CSS) at
> > http://msdn.microsoft.com/subscriptions/support/default.aspx.
> > ==================================================
> > This posting is provided "AS IS" with no warranties, and confers no rights.
> >
> > --------------------
> > >Thread-Topic: CustomValidator in GridView getting "no message" on errors
> > >thread-index: AciFTXs6Q1/KAGdKQoegfeOqrsqbfg==
> > >X-WBNR-Posting-Host: 171.159.64.10
> > >From: =?Utf-8?B?ZG91Zw==?= <dmartin@newsgroups.nospam>
> > >Subject: CustomValidator in GridView getting "no message" on errors
> > >Date: Thu, 13 Mar 2008 14:02:00 -0700
> >
> > >
> > >I have a gridview and have placed customvalidator controls in it.
> > >If I put a break on the sub to do custom validation, run the page, select
> > a
> > >row and press the EDIT button, putting me into Update/Cancel mode, I can
> > edit
> > >the date textbox putting in garbage and press update. It takes the
> > >breakpoint, I step thru, it sets value.isValid=False, and when I exit
> > >routine, same sub fires again (hits same break point) and flow values same
> > >path. Garbage date value still there. If I continue on now, it displays
> > the
> > >gridview, original value of date textbox is back, my error message is not
> > >displayed, but I'm still in Update/Cancel mode,not Edit mode so the update
> > >didn't take place.
> > >
> > > <asp:TemplateField HeaderText="Date Stamp"
> > >SortExpression="date_stamp">
> > > <EditItemTemplate>
> > > <asp:CustomValidator ID="Date_Stamp_Update_Validator"
> > >runat="server"
> > > ControlToValidate="Date_Stamp_Update_Txt"
> > > OnServerValidate="Date_Stamp_Update_Txt_Validate"
> > > ValidateEmptyText="true"
> > > Display="Static"
> > > SetFocusOnError="true"
> > > ErrorMessage="Must be YYYY-MM-DD!" ></asp:CustomValidator>
> > > <asp:TextBox ID="Date_Stamp_Update_Txt"
> > runat="server"
> > >Text='<%# Bind("date_stamp") %>'
> > > BorderStyle="Ridge" BackColor="LightYellow"
> > > MaxLength="10" Width="65px"></asp:TextBox>
> > > </EditItemTemplate>
> > > <ItemTemplate>
> > > <asp:Label ID="Date_Stamp_Label" runat="server"
> > >Text='<%# Bind("date_stamp") %>'></asp:Label>
> > > </ItemTemplate>
> > > <ItemStyle HorizontalAlign="Left" VerticalAlign="Bottom"
> > Width="9%"
> > >Wrap="True"/>
> > > <HeaderStyle VerticalAlign="Bottom" />
> > > </asp:TemplateField>
> > >
> > >
> > > Protected Sub Date_Stamp_Update_Txt_Validate(ByVal sender As Object,
> > ByVal
> > >value As ServerValidateEventArgs)
> > > ' Must be YYYY-MM-DD Format:
> > > If value.Value.ToString.Length = 10 Then
> > > Dim dte As DateTime
> > > If DateTime.TryParse(value.Value, dte) Then
> > > value.IsValid = True
> > > Else
> > > value.IsValid = False
> > > End If
> > > Else
> > > value.IsValid = False
> > > End If
> > > End Sub
> > >
> > >
> > >
> >
> >

RE: CustomValidator in GridView getting "no message" on errors by stcheng

stcheng
Sun Mar 16 20:05:57 CDT 2008

Thanks for your followup dmartin,

I'm glad that you've figured out the issue.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: =?Utf-8?B?ZG91Zw==?= <dmartin@newsgroups.nospam>
>References: <5C052806-8FE6-494B-A58B-28B5B4F3A306@microsoft.com>
<1GxbmqahIHA.360@TK2MSFTNGHUB02.phx.gbl>
<28D03D9A-0E29-410F-9DC4-2635B0061CBC@microsoft.com>
>Subject: RE: CustomValidator in GridView getting "no message" on errors
>Date: Fri, 14 Mar 2008 12:29:00 -0700

>
>I figured it out. I am trying to dynamically modify filtering SQL to add
>additional criteria, and added a DataBing to Page_PreRenderComplete -
which
>isn't working yet, so commenting it out restored errors.
>
>"doug" wrote:
>
>> I added EnableClientScript="false", already had the
"onservervalidate=xxx".
>> This is the routine that is being fired twice, and each time isPostBack
is
>> true, and it fails edit setting isValid="false".
>>
>> Why is this routine fired twice - seemingly one after the other?
>>
>> ""Steven Cheng"" wrote:
>>
>> > Hi dmartin,
>> >
>> > From your description, you found that the custom validator in GridView
not
>> > work correctly , correct?
>> >
>> > I've made a simple test on my side and got a customValidator working
(with
>> > server-side validation) in GridView templateField. I've compared the
code
>> > and aspx template between my test page and yours. It seems there is no
>> > definte difference. I suggest you try the following things:
>> >
>> > ** explicitly turn off client-side validation(disable client script)
>> >
>> > ** Try changing your validation handler in codebehind, use some very
simple
>> > code logic to see whether it work.
>> >
>> > Here is my test page's aspx and codebehind function for your reference:
>> >
>> >
>> > =======aspx ....==
>> > ..............
>> > <asp:TemplateField HeaderText="name" SortExpression="name">
>> > <EditItemTemplate>
>> > <asp:TextBox ID="TextBox1" runat="server"
Text='<%#
>> > Bind("name") %>'></asp:TextBox>
>> > <asp:CustomValidator ID="CustomValidator1"
>> > runat="server" ErrorMessage="CustomValidator"
>> > ControlToValidate="TextBox1"
>> > EnableClientScript="False"
>> >
>> >
onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
>> > </EditItemTemplate>
>> > <ItemTemplate>
>> > <asp:Label ID="Label1" runat="server" Text='<%#
>> > Bind("name") %>'></asp:Label>
>> > </ItemTemplate>
>> > </asp:TemplateField>
>> > =============
>> >
>> >
>> > ===========
>> > protected void CustomValidator1_ServerValidate(object source,
>> > ServerValidateEventArgs args)
>> > {
>> > if (!args.Value.Contains("Name"))
>> > args.IsValid = false;
>> > else args.IsValid = true;
>> >
>> > }
>> > =============
>> >
>> > Sincerely,
>> >
>> > Steven Cheng
>> >
>> > Microsoft MSDN Online Support Lead
>> >
>> >
>> > Delighting our customers is our #1 priority. We welcome your comments
and
>> > suggestions about how we can improve the support we provide to you.
Please
>> > feel free to let my manager know what you think of the level of
service
>> > provided. You can send feedback directly to my manager at:
>> > msdnmg@microsoft.com.
>> >
>> > ==================================================
>> > Get notification to my posts through email? Please refer to
>> >
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
>> > ications.
>> >
>> > Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
>> > where an initial response from the community or a Microsoft Support
>> > Engineer within 1 business day is acceptable. Please note that each
follow
>> > up response may take approximately 2 business days as the support
>> > professional working with you may need further investigation to reach
the
>> > most efficient resolution. The offering is not appropriate for
situations
>> > that require urgent, real-time or phone-based interactions or complex
>> > project analysis and dump analysis issues. Issues of this nature are
best
>> > handled working with a dedicated Microsoft Support Engineer by
contacting
>> > Microsoft Customer Support Services (CSS) at
>> > http://msdn.microsoft.com/subscriptions/support/default.aspx.
>> > ==================================================
>> > This posting is provided "AS IS" with no warranties, and confers no
rights.
>> >
>> > --------------------
>> > >Thread-Topic: CustomValidator in GridView getting "no message" on
errors
>> > >thread-index: AciFTXs6Q1/KAGdKQoegfeOqrsqbfg==
>> > >X-WBNR-Posting-Host: 171.159.64.10
>> > >From: =?Utf-8?B?ZG91Zw==?= <dmartin@newsgroups.nospam>
>> > >Subject: CustomValidator in GridView getting "no message" on errors
>> > >Date: Thu, 13 Mar 2008 14:02:00 -0700
>> >
>> > >
>> > >I have a gridview and have placed customvalidator controls in it.
>> > >If I put a break on the sub to do custom validation, run the page,
select
>> > a
>> > >row and press the EDIT button, putting me into Update/Cancel mode, I
can
>> > edit
>> > >the date textbox putting in garbage and press update. It takes the
>> > >breakpoint, I step thru, it sets value.isValid=False, and when I exit
>> > >routine, same sub fires again (hits same break point) and flow values
same
>> > >path. Garbage date value still there. If I continue on now, it
displays
>> > the
>> > >gridview, original value of date textbox is back, my error message is
not
>> > >displayed, but I'm still in Update/Cancel mode,not Edit mode so the
update
>> > >didn't take place.
>> > >
>> > > <asp:TemplateField HeaderText="Date Stamp"
>> > >SortExpression="date_stamp">
>> > > <EditItemTemplate>
>> > > <asp:CustomValidator ID="Date_Stamp_Update_Validator"
>> > >runat="server"
>> > > ControlToValidate="Date_Stamp_Update_Txt"
>> > > OnServerValidate="Date_Stamp_Update_Txt_Validate"
>> > > ValidateEmptyText="true"
>> > > Display="Static"
>> > > SetFocusOnError="true"
>> > > ErrorMessage="Must be YYYY-MM-DD!" ></asp:CustomValidator>
>> > > <asp:TextBox ID="Date_Stamp_Update_Txt"
>> > runat="server"
>> > >Text='<%# Bind("date_stamp") %>'
>> > > BorderStyle="Ridge" BackColor="LightYellow"
>> > > MaxLength="10" Width="65px"></asp:TextBox>
>> > > </EditItemTemplate>
>> > > <ItemTemplate>
>> > > <asp:Label ID="Date_Stamp_Label"
runat="server"
>> > >Text='<%# Bind("date_stamp") %>'></asp:Label>
>> > > </ItemTemplate>
>> > > <ItemStyle HorizontalAlign="Left" VerticalAlign="Bottom"
>> > Width="9%"
>> > >Wrap="True"/>
>> > > <HeaderStyle VerticalAlign="Bottom" />
>> > > </asp:TemplateField>
>> > >
>> > >
>> > > Protected Sub Date_Stamp_Update_Txt_Validate(ByVal sender As Object,
>> > ByVal
>> > >value As ServerValidateEventArgs)
>> > > ' Must be YYYY-MM-DD Format:
>> > > If value.Value.ToString.Length = 10 Then
>> > > Dim dte As DateTime
>> > > If DateTime.TryParse(value.Value, dte) Then
>> > > value.IsValid = True
>> > > Else
>> > > value.IsValid = False
>> > > End If
>> > > Else
>> > > value.IsValid = False
>> > > End If
>> > > End Sub
>> > >
>> > >
>> > >
>> >
>> >
>