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

  • Thread starter Thread starter Pattabi
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
Back
Top