D
Dan Sikorsky
I'm getting the following message when I try to add a CustomValidator
control to the ValidationSummary to display an error message at runtime, and
displaying ex.message in AddValidationControl shows:
A control cannot modify its parents' control collections.
Here is the code:
Private Function Test() As Boolean
Dim x As Integer = 1
Try
x = x / 0
Catch ex As Exception
AddValidationControl(Me.Page, "frmMain", ex.Message)
End Try
Return True
End Function
In a separate Class Library, I have this function defined:
Public Shared Function AddValidationControl(ByRef PageControl As Page, ByRef
sFormName As String, _
ByRef sMessage As String) As Boolean
Dim valOther As System.Web.UI.WebControls.CustomValidator
Dim objForm As System.Web.UI.HtmlControls.HtmlForm
Dim blnReturn As Boolean
Try
If PageControl Is Nothing Then
Throw New Exception("PageControl was not set and has a value of
Nothing.")
Else
valOther = New System.Web.UI.WebControls.CustomValidator
valOther.ErrorMessage = sMessage
valOther.IsValid = False
valOther.Display = System.Web.UI.WebControls.ValidatorDisplay.None
objForm = PageControl.FindControl(sFormName)
objForm.Controls.Add(valOther) // exception occurs
on this line
blnReturn = True
End If
Catch ex As Exception
ex = Nothing
End Try
Return blnReturn
End Function
How can I resolve this error?
Thank you kindly,
Dan Sikorsky
control to the ValidationSummary to display an error message at runtime, and
displaying ex.message in AddValidationControl shows:
A control cannot modify its parents' control collections.
Here is the code:
Private Function Test() As Boolean
Dim x As Integer = 1
Try
x = x / 0
Catch ex As Exception
AddValidationControl(Me.Page, "frmMain", ex.Message)
End Try
Return True
End Function
In a separate Class Library, I have this function defined:
Public Shared Function AddValidationControl(ByRef PageControl As Page, ByRef
sFormName As String, _
ByRef sMessage As String) As Boolean
Dim valOther As System.Web.UI.WebControls.CustomValidator
Dim objForm As System.Web.UI.HtmlControls.HtmlForm
Dim blnReturn As Boolean
Try
If PageControl Is Nothing Then
Throw New Exception("PageControl was not set and has a value of
Nothing.")
Else
valOther = New System.Web.UI.WebControls.CustomValidator
valOther.ErrorMessage = sMessage
valOther.IsValid = False
valOther.Display = System.Web.UI.WebControls.ValidatorDisplay.None
objForm = PageControl.FindControl(sFormName)
objForm.Controls.Add(valOther) // exception occurs
on this line
blnReturn = True
End If
Catch ex As Exception
ex = Nothing
End Try
Return blnReturn
End Function
How can I resolve this error?
Thank you kindly,
Dan Sikorsky