473,396 Members | 2,085 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,396 software developers and data experts.

customvalidator problem in datagrid

hi,

i have a textbox in my edititemtemplate in my datagrid. I have created
a customvalidator for it, when i update the row the appropiate
function gets called to customvalidate but the problem is that the
error message in my customvalidator does not get printed in the
datagrid even though I have set the isvalid property in the server
function to false. Does anyone know why this is?

Here is the code snippets:

protected void cbLangCheck(object source, ServerValidateEventArgs
args)
{
if(insert_lang.Items.FindByText(args.Value) == null)
{
args.IsValid = false;
return;
}
else
{
args.IsValid = true;
return;
}

}

<asp:TemplateColumn HeaderStyle-CssClass="header"
HeaderText="External Ref">
<ItemTemplate>
<asp:Label runat="server" ID="extref"
Text='<%#DataBinder.Eval(Container.DataItem, "ExtRefKey")%>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox CssClass="standard-text" ID="extrefentry"
Text='<%#tmsettings.ExtRef%>' runat="server" />
<asp:CustomValidator Runat="server"
EnableClientScript="False" ControlToValidate="extrefentry"
OnServerValidate="tbrefCheck" ErrorMessage="You must select language
from list" Display="Dynamic"></asp:CustomValidator>
</EditItemTemplate>
</asp:TemplateColumn>
Nov 18 '05 #1
3 1837
Hi PhilipL, I guess you xposted this on www.asp.net. Thanks for adding the
code.

The overall code looks good although I'd like to know if the server validate
method is actually called.

Here's what I think may be happening.
1. Your page is posted back.
2. The Page.Validate method runs (probably automatically in the Submit
button)
3. Now this method is called and it returns IsValid=false (as you prove with
a debugger)
4. You call DataBind() on the datagrid, forcing it to recreate the entire
grid's rows.

Its easy to clobber rows in a DataGrid...

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

<ph*****@vistatec.ie> wrote in message
news:a3**************************@posting.google.c om...
hi,

i have a textbox in my edititemtemplate in my datagrid. I have created
a customvalidator for it, when i update the row the appropiate
function gets called to customvalidate but the problem is that the
error message in my customvalidator does not get printed in the
datagrid even though I have set the isvalid property in the server
function to false. Does anyone know why this is?

Here is the code snippets:

protected void cbLangCheck(object source, ServerValidateEventArgs
args)
{
if(insert_lang.Items.FindByText(args.Value) == null)
{
args.IsValid = false;
return;
}
else
{
args.IsValid = true;
return;
}

}

<asp:TemplateColumn HeaderStyle-CssClass="header"
HeaderText="External Ref">
<ItemTemplate>
<asp:Label runat="server" ID="extref"
Text='<%#DataBinder.Eval(Container.DataItem, "ExtRefKey")%>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox CssClass="standard-text" ID="extrefentry"
Text='<%#tmsettings.ExtRef%>' runat="server" />
<asp:CustomValidator Runat="server"
EnableClientScript="False" ControlToValidate="extrefentry"
OnServerValidate="tbrefCheck" ErrorMessage="You must select language
from list" Display="Dynamic"></asp:CustomValidator>
</EditItemTemplate>
</asp:TemplateColumn>

Nov 18 '05 #2
"Peter Blum" <PL****@Blum.info> wrote in message news:<uE*************@TK2MSFTNGP10.phx.gbl>...
Hi PhilipL, I guess you xposted this on www.asp.net. Thanks for adding the
code.

The overall code looks good although I'd like to know if the server validate
method is actually called.

Here's what I think may be happening.
1. Your page is posted back.
2. The Page.Validate method runs (probably automatically in the Submit
button)
3. Now this method is called and it returns IsValid=false (as you prove with
a debugger)
4. You call DataBind() on the datagrid, forcing it to recreate the entire
grid's rows.

Its easy to clobber rows in a DataGrid...

Thanks Peter,

that actually pointed me to the right direction. Yeah, indeed right
after checking, it is going straight to the update event and rebinding
the entire datagrid. Now I just check for status of isvalid at in the
update event and prevent it from rebinding if necessary. It's hard to
get into a debugging mindset with .net, since everything is supposed
to be straight forward.
Nov 18 '05 #3
I'm glad it worked.

You wrote: "It's hard to
get into a debugging mindset with .net, since everything is supposed
to be straight forward."
It think its usually pretty straightforward. But I come from years of OOP
experience. I live for classes to represent everything.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

<ph*****@vistatec.ie> wrote in message
news:a3**************************@posting.google.c om... "Peter Blum" <PL****@Blum.info> wrote in message

news:<uE*************@TK2MSFTNGP10.phx.gbl>...
Hi PhilipL, I guess you xposted this on www.asp.net. Thanks for adding the code.

The overall code looks good although I'd like to know if the server validate method is actually called.

Here's what I think may be happening.
1. Your page is posted back.
2. The Page.Validate method runs (probably automatically in the Submit
button)
3. Now this method is called and it returns IsValid=false (as you prove with a debugger)
4. You call DataBind() on the datagrid, forcing it to recreate the entire grid's rows.

Its easy to clobber rows in a DataGrid...

Thanks Peter,

that actually pointed me to the right direction. Yeah, indeed right
after checking, it is going straight to the update event and rebinding
the entire datagrid. Now I just check for status of isvalid at in the
update event and prevent it from rebinding if necessary. It's hard to
get into a debugging mindset with .net, since everything is supposed
to be straight forward.

Nov 18 '05 #4

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

Similar topics

0
by: Christophe | last post by:
hi everyone, i' ve got a datagrid in which there is a column with an input texbox in the column "template", i've added a customvalidator an one button this validator is here to check the input...
1
by: bill yeager | last post by:
I'm using the customvalidator in my web page. I get the following error when I try to run the web page: Unable to find control id 'lstRider' referenced by the 'ControlToValidate' property of...
1
by: Dave | last post by:
I have added a custom validator to the EditItemTemplate of a DataGrid as follows: <EditItemTemplate> <asp:TextBox id=txtWorkDate CssClass="ResultsDim" runat="server" Width="100%" Text='<%#...
1
by: Jim Heavey | last post by:
Hello, I was am wanting to validate that a user has made a selection from a dropdownlist control in a datagrid. Is my only option to use a "CustomValidator Control"? I am not quite sure how to...
5
by: Gene McCrory | last post by:
Is it possible to have a CustomValidator against two controls in an EditItemTemplate on a DataGrid? Case: Have a business rule that states if ATextBox starts with "ACertainValue" then BTextBox...
1
by: 2obvious | last post by:
I'm using a CustomValidator within a datagrid control. I'd like to get the index of the item (i.e. row of the datagrid) when the validator is fired and use this number in my custom function. Can...
2
by: 2obvious | last post by:
Below is a cut-and-paste code example that runs. It demonstrates some results which confuse me. It uses a DataGrid to make a table with 12 rows, each containing a TextBox and a CustomValidator....
0
by: ghafranabbas | last post by:
This is how you use the customvalidator control in any INamingContainer interface control (Datagrid, DataList, DataRepeater, etc). 1. In the ItemTemplate, place your customvalidator 2. Set the...
2
by: andrewhharmon | last post by:
I am trying to use a custom validator to check if a duplicate email exist in my database when i use the update button in a datagrid. The update button calls a stored procedure in SQL that checks...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.