Solved

Expert: Error validation after page has been submited.

Posted on 2004-08-13
10
224 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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