Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Expert: Error validation after page has been submited.

Posted on 2004-08-13
10
Medium Priority
?
231 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1000 total points
ID: 11807885
0
 
LVL 8

Assisted Solution

by:boulder_bum
boulder_bum earned 1000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

916 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