Solved

Expert: Error validation after page has been submited.

Posted on 2004-08-13
10
221 Views
Last Modified: 2010-04-07
I am building a form that adds up to 25 users at a time. However since the may not all be filled in maybe only 15 at at time I would like to do Error checking after the user has clicked submit then post the error back to the tablecell for the textbox that has problems. So for instance here if if not txtName2 is Nothing then Inet must be selected. I will also be doning phone number, and email validation.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'build table
        Dim i As Integer

        For i = 0 To 25
            Dim tr As TableRow = New TableRow

            'make name cell with validator
            Dim tc1 As TableCell = New TableCell

            Dim txtName As TextBox = New TextBox
            txtName.ID = "txtName" + i.ToString()

            tc1.Controls.Add(txtName)
            tr.Cells.Add(tc1)

            Dim tcInet As TableCell = New TableCell
            Dim txtDial As RadioButton = New RadioButton
            Dim txtBroadband As RadioButton = New RadioButton

            txtDial.ID = "txtINet" + i.ToString()
            txtBroadband.ID = "txtINet" + i.ToString()

            tcINet.Controls.Add(txtDial)
            tcINet.Controls.Add(txtBroadband)

            tr.Cells.Add(tcINet)
     


            Table1.Rows.Add(tr)
        Next
   End Sub

Sub Button_Click( s As Object, e As EventArgs )
dim txtName2 As TextBox
   txtName2 = CType(Me.Page.FindControl("txtName2"),TextBox)
   if not txtName2 is Nothing then
      Response.Write(txtName2.Text)
   end if
End Sub


0
Comment
Question by:jui2ce
10 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 11791484
Hi,

i think i don't understand quite what you want
you want to perform checks on the information entered in a field in your form and if the value is ok for you to submit the page, otherwise to output a message to the user to correct the field, showing which field is wront, correct ?

Regards,
B..M
0
 
LVL 8

Expert Comment

by:boulder_bum
ID: 11794217
"f not txtName2 is Nothing then Inet must be selected"

For a circumstance like that, you'd want a "CustomValidator" that could check for those conditions. See here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolscustomvalidatorclasstopic.asp

"I will also be doning phone number, and email validation"

This is a job for the ReqularExpressionValidator, which can be attached to the appropriate TextBoxes (I believe the RegEx validator even has built-in expressions you can select to handle phone numbers and e-mail addresses). Of note is that the RegEx validator will only fire if input is present, so it won't fire for a row where you really want to leave the input blank.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsregularexpressionvalidatorclasstopic.asp
0
 

Author Comment

by:jui2ce
ID: 11796887
Problem with using Validators is I don't want the row to be validated unless there is something in the name(first textbox of 5). That way if a person only adds 15 it only validates those 15 not all 25
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 8

Expert Comment

by:boulder_bum
ID: 11797783
Yes. The latter two validators I mentioned won't fire/try to validate if the inputs in a given row are blank, and the custom validator will support any sort of logic you wish (for example checking to make sure every input in a row is filled out if "name" has a value).

Validator controls are certainly the way to go here, it's just a matter of figuring out which to use and how to use them.
0
 

Author Comment

by:jui2ce
ID: 11798092
I do not see the example of how to validate depending if the first textbox. Could you please show me an example?
0
 
LVL 20

Accepted Solution

by:
ihenry earned 250 total points
ID: 11807885
0
 
LVL 8

Assisted Solution

by:boulder_bum
boulder_bum earned 250 total points
ID: 11815636
Basically for a CustomValidator, there's a ServerValidate event you can hook and an optional ClientValidationFunction (which uses client-side JavaScript for validation).

Sub ServerValidation(source As Object, args As ServerValidateEventArgs)

         'if first textbox in row is empty or all textboxes in row aren't empty
         args.IsValid = true

        'otherwise
        args.IsValid = false

End Sub

For an example of the javascript model used for validator controls, see here:

http://www.aspfree.com/c/a/ASP.NET/Improved-Input-Validation/4/


Your challenge is going to be getting the index of the row you want, and finding all of the related controls. I'd recommend referencing the parent row of the control found in the ControlToValidate property (use the first TextBox of the row), then looking at its child controls of the row to find all of your TextBoxes. If you need more help, feel free to drop a note.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now