Referencing a control in Javascript

J

John

Hi all,

In my code-behind, I validate some controls and if a particular control has
a problem, I not only send an alert down to the client via
Page.RegisterStartupScript but I'd like to set the focus of the control. now
the control in question is embedded into a user control which is, in turn,
embedded into a user control which, in turn, is embedded onto a web form.

The Javascript does not work if I when I refernce the control with it's ID.
I checked the client source and saw it was renamed to
'_ctl2_UCIngDetail_lstUnits2'. Now when I changed the Javascript to
'document.frmMain._ctl2_UCIngDetail_lstUnits2.focus();', this worked. but
isn't this going to break if controls are added to the usercontrol?

What is the correct way to solve this dilemma?

Regards
John.
 
P

PJ Lee

You will need to use the "ClientID" property of the control to reference it
properly.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top