customvalidator problem in datagrid

P

philipl

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>
 
P

Peter Blum

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: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
P

philipl

Peter Blum said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top