Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

CustomValidator issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jmclej@hotmail.com - 19 Oct 2005 14:07 GMT
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
Remy - 19 Oct 2005 14:13 GMT
Not the answer to your question, but since you are only doing a RegEx
test, why don't you use the RegularExpression Validator?

Remy Blaettler
www.collaboral.com
jmclej@hotmail.com - 19 Oct 2005 14:25 GMT
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
Remy - 19 Oct 2005 14:40 GMT
Didn't see that you are doing this in a DataGrid (I assume).
Here is a nice example with source code (view source link)

http://www.daveandal.net/books/6744/webforms/validate-datagrid.aspx

Hope that helps

Remy Blaettler
www.collaboral.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.