469,573 Members | 1,507 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,573 developers. It's quick & easy.

Mental Block - probably easy answer...validation summary

Hi all,

I have a login page which has username and password fields, a login button,
and 2 validation controls (one for each field) - currently I have controls
to display to the summary if the items missing etc.all working fine...

However, when the user logs in I fire off to a stored procedure, at this
point, unless the login is successful I can return up to about 8 different
error numbers in a string which I then split out into an array...

What I'd normally do in 'vanilla' ASP would be to iterate through the return
array and display a set of <tr><td></td></tr>'s etc for each error
message....I am at a complete loss as to how I do this in ASP.Net without
the use of labels?

Is it possible that I could add items to the validation summary at the
bottom of the page using my own error messages based on the returned error
code?

If not, how would I go about doing what i mentioned above, ie, producing
several rows in a table on the page? And if thats possible, would it also
be possible to remove the standard validation summary and upon the fields
being left empty, my table up top gets populated with the error messages
instead?

Any help would be apprecaited - and the easier to follow/understand the
better :o)

Many thanks for your time.

Regards

Rob
Nov 18 '05 #1
3 2146
How much work do you want to do?

The validation summary can be added to, but it is not a straightforward
process. It is facilitated by creating your own validation controls that
write out a message for the summary control. As the methodology is rather
standardized (which events fired, et al), you can hijack this functionality
to add your messages to the control by making a validation control.

On the other hand, you are creating functionality that is a bit kludgy when
you create a "validation control" that does not really validate, so the
label method is a working method. You can also set up a container control
(panel, et al) and add literals (which are lighter in client tags than the
label) to the container.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi all,

I have a login page which has username and password fields, a login button, and 2 validation controls (one for each field) - currently I have controls
to display to the summary if the items missing etc.all working fine...

However, when the user logs in I fire off to a stored procedure, at this
point, unless the login is successful I can return up to about 8 different
error numbers in a string which I then split out into an array...

What I'd normally do in 'vanilla' ASP would be to iterate through the return array and display a set of <tr><td></td></tr>'s etc for each error
message....I am at a complete loss as to how I do this in ASP.Net without
the use of labels?

Is it possible that I could add items to the validation summary at the
bottom of the page using my own error messages based on the returned error
code?

If not, how would I go about doing what i mentioned above, ie, producing
several rows in a table on the page? And if thats possible, would it also
be possible to remove the standard validation summary and upon the fields
being left empty, my table up top gets populated with the error messages
instead?

Any help would be apprecaited - and the easier to follow/understand the
better :o)

Many thanks for your time.

Regards

Rob

Nov 18 '05 #2
"Cowboy (Gregory A. Beamer)" wrote...
How much work do you want to do?
Not much! :D
The validation summary can be added to, but it is not a straightforward
process. It is facilitated by creating your own validation controls that
write out a message for the summary control. As the methodology is rather
standardized (which events fired, et al), you can hijack this functionality to add your messages to the control by making a validation control.

On the other hand, you are creating functionality that is a bit kludgy when you create a "validation control" that does not really validate, so the
label method is a working method. You can also set up a container control
(panel, et al) and add literals (which are lighter in client tags than the
label) to the container.

*WHOOOSH*

Ok - completely over my head all of that....

I'm currently looking at the add table row / table cell dynamically etc -
but even that wont work - grrr - even using the example in the help file
with Visual Studio and likewise on the MS site - I suspect I have to put a
IMPORTS at the top of the page or something - but as usual no mention is
made of this in the help :o(

Any ideas...

This is what I'm trying :

Dim tRow As New TableRow()
Table1.Rows.Add(tRow)

When I try to use this in my code - the Dim line REMOVES the brackets at the
end of TableRow

Then the second line has the purple scribble under tRow...

Not my day :(

Regards

Rob
Nov 18 '05 #3
Apologies for going over your head. It will become clear over time.

There are basically two ways to add items to a page like you describe.

1. Make your own validation control. This is the *whoosh* you described, as
it requires some understanding of derived classes.
2. Add your own controls to the page that handle the special messages.

I will examine #2, as that is what you are trying (comments inline):

"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message
news:eq**************@tk2msftngp13.phx.gbl...

I'm currently looking at the add table row / table cell dynamically etc -
but even that wont work - grrr - even using the example in the help file
with Visual Studio and likewise on the MS site - I suspect I have to put a
IMPORTS at the top of the page or something - but as usual no mention is
made of this in the help :o(

Any ideas...

This is what I'm trying :

Dim tRow As New TableRow()
Table1.Rows.Add(tRow)

When I try to use this in my code - the Dim line REMOVES the brackets at the end of TableRow


The disappearing () is quite normal with Visual Basic. The problem is you
have not added any cells to the row. Here is an example that uses a label to
render some text.

Dim tr As New TableRow
Dim tc As New TableCell
Dim lbl As New Label
lbl.Text = "This is some sample text"
tc.Controls.Add(lbl)
tr.Cells.Add(tc)
Table1.Rows.Add(tr)

NOTE: You can also use a literal.

Dim tr As New TableRow
Dim tc As New TableCell
tc.Controls.Add(New LiteralControl("This is some sample text"))
tr.Cells.Add(tc)
Table1.Rows.Add(tr)

Literals are a little lighter, although you will not be able to position as
easily. As you are using a table, this is not a problem. NOTE that you could
do this a bit more longhand, if you wish:

Dim tr As New TableRow
Dim tc As New TableCell
Dim lit As new LiteralControl("This is some sample text"))

tc.Controls.Add(New LiteralControl(lit)
tr.Cells.Add(tc)
Table1.Rows.Add(tr)

Do not get overdrawn on the specifics here, just play with the code and you
will feel more comfortable. You can now loop, for example, through a loop of
validation error messages, like so:

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

'Get validation errors
' Assuming an array here, have to alter for other forms
Dim aryString() As String = ValidateErrors()

'Set up counter for the loop
Dim intCounter As Integer

For intCounter = 0 To UBound(aryString)
Dim tr As New TableRow
Dim tc As New TableCell
tc.Controls.Add(New LiteralControl(aryString(intCounter)))
tr.Cells.Add(tc)
Table1.Rows.Add(tr)
Next
End Sub

'NOTE: This is simply to test, create a true validation routine
' instead of this kludge
Private Function ValidateErrors() As String()
'Simple array; yours will come from validation
Dim outputString() As String = {"Validation error 1", _
"Validation error 2", "Validation Error 3"}

'Return the array for processing in Page_Load
Return outputString
End Function
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by craig | last post: by
1 post views Thread by NancyASAP | last post: by
1 post views Thread by Buddy Ackerman | last post: by
2 posts views Thread by nmakhan | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.