Link to home
Start Free TrialLog in
Avatar of HLRosenberger
HLRosenbergerFlag for United States of America

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
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
Avatar of HLRosenberger

ASKER

ah, got it!
I removed the table.   That did not help.,  I also added ClientIDMode="Static" to the txtFirstName control.  Still no luck,.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There must be a way.
You were correct.  I change the code to dynamically add the controls to the Page.Form

  Private rnd As New Random(DateTime.Now.Millisecond)

Public Sub AddControl(ControlToValidate 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