CustomValidator issue

J

jmclej

Here is what I have :

<asp:templatecolumn HeaderText="HrBegin">
<itemtemplate>
<asp:Label id="lblHrBegin" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "HrBegin") %>' Width="100%">
</asp:label>
</itemtemplate>
<footertemplate>
<asp:textbox id="tbHrBeginInsert" runat="server"
Width="100%"></asp:textbox>
<asp:CustomValidator id="Customvalidator1"
ControlToValidate="tbHrBeginInsert" OnServerValidate="ServerValidation"
Display="None" runat="server"></asp:CustomValidator>
</footertemplate>
<edititemtemplate>
<asp:textbox id="tbHrBegin" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.HrBegin") %>'
Width="100%"></asp:textbox>
<asp:CustomValidator id="Customvalidator2"
ControlToValidate="tbHrBegin" OnServerValidate="ServerValidation"
Display="None" runat="server"></asp:CustomValidator>
</edititemtemplate>
</asp:templatecolumn>


Code Behind:

void ServerValidation(object source, ServerValidateEventArgs args) {
try
{
Regex r = new
Regex("(([0-1][0-9])|(2[0-3])):([0-5][0-9]):([0-5][0-9])"); //Only
allow "02:03:04"
Match m = r.Match(args.Value);
// Test whether the value entered into the text box is in a correct
hour format.
if (m.Success)
args.IsValid = true;
else
args.IsValid = false;
}
catch(Exception ex)
{
args.IsValid = false;
}
}

I put the ServerValidation() function on the code behind because I
thought that this was the way of doing server-side validation. But it
actually works only if I put this function inside a script block on the
aspx page, which looks like then client-side validation, no? Maybe I
need to add something in the InitializeComponent() method?
But anyway, even like this there is still something that is not good.
It's that I get all the time the same text to be validated, that is the
content of my itemtemplate. What should I do to make ServerValidation()
to test the new data entered in the textbox tbHrBeginInsert or
tbHrBegin?
Thank you very much for your help.
JULIEN
 
J

jmclej

euuuuhhh because I hadn't seen it actually :-( Thank you!
I then changed it, but still, I get the same problem, that is the value
evaluated is not the one I enter in the edititemtemplate, but only the
inital value set in itemtemplate.
Any idea someone?
Cheers,
JULIEN
 

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

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top