Why the Id of the user control gets changed when used in aspx

P

Pattabi

Hi guys!!!!!!!!!
Can anyone help me out in this. I have .ascx file with one
textbox control in it. I am using it in my .aspx file. What happens is
i am giving the id of textbox control in ascx as ID="text1" when i try
to view the source once the page is loaded i can see the id as
"ctl4_text1". why is that. I need the Id because i need to do
validations for that control

can someone help me in this!!!!!!!!!!!

thanks
dharani pattabi
 
J

Jonel Rienton

Pattabi said:
Hi guys!!!!!!!!!
Can anyone help me out in this. I have .ascx file with one
textbox control in it. I am using it in my .aspx file. What happens is
i am giving the id of textbox control in ascx as ID="text1" when i try
to view the source once the page is loaded i can see the id as
"ctl4_text1". why is that. I need the Id because i need to do
validations for that control

can someone help me in this!!!!!!!!!!!

thanks
dharani pattabi

Pattabi,

would you be doing server or client side validation?

Jonel
 
D

Dharani Ravindran

Hi jonel,
thanks for immediate response. I need to do serverside valiation
using
validationcontrols
<asp:comparevalidator....requiredvalidator
since the id is changed during the load, the controls is not getting
validated.

waiting for your response

thanks
dharni
 
S

SF

Dharani,

the problem you are facing is that you have wrapped your text control in a
custom user control,
therefore the control gets renamed to "ctl4_text1", where ctl4 is the id of
your user control.
This is to allow for multiple instances of the same user control on the same
page without naming
collisions (since forms send back in http in key-value-pairs).

VS.Net does not support your approach and I haven't found a solution for
your problem.
I tried dynamically setting the controlToValidate in the validator, but it
only takes a string value
(otherwise you could have looked up the text control using FindControl())

Let me know if you found a solution
Good luck
Stefan
 
S

SF

Dharani,

the problem you are facing is that you have wrapped your text control in a
custom user control,
therefore the control gets renamed to "ctl4_text1", where ctl4 is the id of
your user control.
This is to allow for multiple instances of the same user control on the same
page without naming
collisions (since forms send back in http in key-value-pairs).

VS.Net does not support your approach and I haven't found a solution for
your problem.
I tried dynamically setting the controlToValidate in the validator, but it
only takes a string value
(otherwise you could have looked up the text control using FindControl())

Let me know if you found a solution
Good luck
Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top