Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Expert: Error validation after page has been submited.

Posted on 2004-08-13
10
Medium Priority
?
229 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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 …
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

688 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