[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

Getting Validation Summary info

Is there a way to extract error messages contained in ValidationSummary control?

Thanks
0
gromul
Asked:
gromul
1 Solution
 
mmarinovCommented:
I don't know what is the purpose of your question ( i don't see the need ) , but actually you can not directly get the messages from the ValidationSummary. This control get the errormessages from every validator on your page

so you can use something like this

vb
Dim vc as ValidatorControl = Page.Validators
Dim Index as Integer

For Index=0 To vc.Count-1
 Response.Write(vc(Index).ErrorMessage)
Next


c#
ValidatorCollection vc = Page.Validators;
for ( int index=0; index < vc.Count; vc++ )
  Response.Write(vc[index].ErrorMessage);

HTH
B..G
0
 
gromulAuthor Commented:
Thanks mmarinov
0
 
tigriswoodsCommented:
This answer gave me what I needed, but it actually gives the text  of all the validators, whether they are valid or not.

I am loading a form from XML data and will automatically move to another page if there is no error. However, if there is an error, I have to save the errors.  I refined the accepted answer so that I see only the validators where Isvalid = false.

 Validate("UserInfo")
        If Not IsValid Then
            Dim RxErrors As String = ""
            Dim vc As ValidatorCollection = Page.Validators
            Dim Index As Integer

            For Index = 0 To vc.Count - 1
               If vc.Item(Index).IsValid = False Then
                    RxErrors += "<Error>" & (vc(Index).ErrorMessage) & "</Error>"
                End If

            Next
            If RxErrors.Trim.Length > 0 Then
                RxErrors = "<Errors>" & RxErrors & "</Errors>"
            End If


        End If
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now