+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 11 to 19 of 19

Thread: Validation Function / Class

  1. #11
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    1,724
    Blog Entries
    10
    Rep Power
    11

    Quote Originally Posted by jmurrayhead View Post
    Code:
    <asp:TextBox ID="TextBox1" runat="server" />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
           ControlToValidate="TextBox1"
           Display="Dynamic"
           ErrorMessage="TextBox1 is required" 
           Text="*" />
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
           ControlToValidate="TextBox1"
           Display="Dynamic"
           ErrorMessage="TextBox1 contains invalid characters"
           Text="*"
           ValidationExpression="^[a-zA-Z]$" />
    
    This requires the use of the ValidationSummary control to display all error messages in a box together.
    So, in the case that textbox1 was blank, just the TextBox1 is required text would show and in the case someone entered 12345, just TextBox1 contains invalid characters would show?

    And, in the example I gave, you could change <asp: panel> control to ValidationSummary and all error messages for all validation controls would show here?

  2. #12
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    1,724
    Blog Entries
    10
    Rep Power
    11

    Quote Originally Posted by micky View Post
    Nice.
    So then server side validation can be by-passed!!

    Lot of code would have been saved by me
    m, I think using validation controls is server side validation. They are .NET controls, after all.

  3. #13
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Washington, D.C.
    Posts
    2,347
    Blog Entries
    9
    Rep Power
    19

    Quote Originally Posted by micky View Post
    Nice.
    So then server side validation can be by-passed!!

    Lot of code would have been saved by me
    Indeed

    Quote Originally Posted by richyrich View Post
    So, in the case that textbox1 was blank, just the TextBox1 is required text would show and in the case someone entered 12345, just TextBox1 contains invalid characters would show?

    And, in the example I gave, you could change <asp: panel> control to ValidationSummary and all error messages for all validation controls would show here?
    Yes, Yes and Yes!!

    Quote Originally Posted by richyrich View Post
    m, I think using validation controls is server side validation. They are .NET controls, after all.
    As long as you perform the validation check using Page.IsValid as I have shown
    jmurrayhead
    If you agree, give me rep. If my post helped you, click "Thanks".
    If you like it here...throw us a few bones to help support us.


  4. #14
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    683
    Blog Entries
    1
    Rep Power
    6

    Quote Originally Posted by richyrich View Post
    So, in the case that textbox1 was blank, just the TextBox1 is required text would show and in the case someone entered 12345, just TextBox1 contains invalid characters would show?
    Yes, you'll need separate required validators and regular validator for 1 control.
    And each for other controls that you want to validate.

    Quote Originally Posted by richyrich View Post
    And, in the example I gave, you could change <asp: panel> control to ValidationSummary and all error messages for all validation controls would show here?
    ValidationSummary can show a message box or also can post the error like on a label

    Quote Originally Posted by richyrich View Post
    m, I think using validation controls is server side validation. They are .NET controls, after all.
    I think they use javascript to fire, so if the js is disables, then they might not fire and hence the need for server side validation.

  5. #15
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Washington, D.C.
    Posts
    2,347
    Blog Entries
    9
    Rep Power
    19

    Quote Originally Posted by micky View Post
    I think they use javascript to fire, so if the js is disables, then they might not fire and hence the need for server side validation.
    They use JavaScript to fire the client-side validation, but using Page.IsValid on the server will fire the server-side validation that is defined by each validation control:
    Code:
    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
        If Page.IsValid Then
            ' Code to save the record here
        End If
    End Sub
    
    jmurrayhead
    If you agree, give me rep. If my post helped you, click "Thanks".
    If you like it here...throw us a few bones to help support us.


  6. #16
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    683
    Blog Entries
    1
    Rep Power
    6

    thats good to know J

  7. #17
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    1,724
    Blog Entries
    10
    Rep Power
    11

    Would it be able to handle the scenario where you might have two submit controls where one submits the form in full and the other only checks a few of the textboxes?

    Say, for example, you have a form that has name, date of birth and address details and a button that prepopulates a series of address textboxes if the user just enters a postcode / zipcode.

    So, you want to validate the postcode, zipcode is valid when prepopulating the address, but you don't want to validate the name and date of birth fields until the full form is submitted.

    How would you handle this using validation controls? I presume if you used Page.IsValid in the GetAddress function, it would pick up the name and date of birth validations as well.

  8. #18
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Washington, D.C.
    Posts
    2,347
    Blog Entries
    9
    Rep Power
    19

    Validation controls have a property called "ValidationGroup" where you would set the name (i.e. ValidationGroup="SaveRecord"). You would have to assign the ValidationGroup property of the individual buttons, using the same name as the form items they are to validate.
    jmurrayhead
    If you agree, give me rep. If my post helped you, click "Thanks".
    If you like it here...throw us a few bones to help support us.


  9. #19
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    1,724
    Blog Entries
    10
    Rep Power
    11

    Just in case anyone comes across this thread for information, I had to change the validation expression to below:-
    Code:
                        <asp:RegularExpressionValidator ID="revForename" runat="server" ControlToValidate="txtForename"
                            ErrorMessage="The forename you entered contains invalid characters" ValidationExpression="^[a-zA-Z ]+$"
                            Display="None" EnableClientScript="true" />
    
    Otherwise it wouldn't accept the text I entered.

+ Reply to Thread
Page 2 of 2 FirstFirst 1 2

Similar Threads

  1. Email Class
    By jmurrayhead in forum .Net Code Samples
    Replies: 2
    Last Post: July 8th, 2009, 07:49 AM
  2. Button Class
    By richyrich in forum HTML & CSS Help
    Replies: 18
    Last Post: February 27th, 2009, 12:32 PM
  3. class name is ambiguous
    By richyrich in forum .Net Development
    Replies: 11
    Last Post: August 12th, 2008, 11:11 AM
  4. FTP Class Library?
    By Wolffy in forum .Net Development
    Replies: 6
    Last Post: May 30th, 2008, 10:26 AM
  5. Class library
    By Shem in forum .Net Development
    Replies: 11
    Last Post: May 22nd, 2008, 07:01 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO