Solved

Expert: Error validation after page has been submited.

Posted on 2004-08-13
10
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

635 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