Avatar of HLRosenberger
HLRosenberger
Flag 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
ASP.NET.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
HLRosenberger

8/22/2022 - Mon
Nasir Razzaq

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

ASKER
ah, got it!
HLRosenberger

ASKER
I removed the table.   That did not help.,  I also added ClientIDMode="Static" to the txtFirstName control.  Still no luck,.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Nasir Razzaq

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
HLRosenberger

ASKER
There must be a way.
HLRosenberger

ASKER
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