HLRosenberger
asked on
Help with User Control
I'm creating a User Control. I have attached the ascx and ascx.vb. I have also attached the aspx and aspx.vb for the page where I am using the control. Also attached an error message I get when I run. Question - why the error, why can it not find my txtFirstName control?
ascx.png
ascx.vb.png
aspx.png
aspx.vb.png
error.png
ascx.png
ascx.vb.png
aspx.png
aspx.vb.png
error.png
Its because the textbox is in a table and will be repeated for each row so it is not unique. For controls that inside repeating controls like gridview items, repeater, tables etc, you can not reference these directly.
ASKER
ah, got it!
ASKER
I removed the table. That did not help., I also added ClientIDMode="Static" to the txtFirstName control. Still no luck,.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
There must be a way.
ASKER
You were correct. I change the code to dynamically add the controls to the Page.Form
Private rnd As New Random(DateTime.Now.Millis econd)
Public Sub AddControl(ControlToValida te As String, ErrorMessage As String)
Dim req As New RequiredFieldValidator
Dim ext As New ValidatorCalloutExtender
req.ControlToValidate = ControlToValidate
req.ErrorMessage = ErrorMessage
req.Display = ValidatorDisplay.None
req.ID = "req" & Rnd.Next
ext.TargetControlID = req.ID
ext.ID = "ext" & rnd.Next
Page.Form.Controls.Add(req )
Page.Form.Controls.Add(ext )
End Sub
Private rnd As New Random(DateTime.Now.Millis
Public Sub AddControl(ControlToValida
Dim req As New RequiredFieldValidator
Dim ext As New ValidatorCalloutExtender
req.ControlToValidate = ControlToValidate
req.ErrorMessage = ErrorMessage
req.Display = ValidatorDisplay.None
req.ID = "req" & Rnd.Next
ext.TargetControlID = req.ID
ext.ID = "ext" & rnd.Next
Page.Form.Controls.Add(req
Page.Form.Controls.Add(ext
End Sub