Javascrpt and User Controls. Help!

G

Guest

Hello,

I'm trying to change a links href with javascript. I know that asp.net will
change the controls ids to protect against multiple controls on a page. So I
use the following code.

var buttonId = <%= this.FindControl("imgLinkRead").ClientID %>;

The problem is that imgLinkRead is a user control, so it is a control within
a control. If I look at the source the id imgLinkRead is
'Features1_imgLinkRead_imageLink'. How to I get that from javascript? I
need help ASAP. Thanks
 
L

LVP

The same way Bind in Javascript
or
Inject your custom made Javascript to browser.

you already have it.
 
K

Kevin Spencer

The FindControl method operates on the immediate children of the Control you
specify. If you want the ClientID of a Control inside the UserControl, you
have to call FindControl on the UserControl. Example:

((UserControlName)this.FindControl("imgLinkRead")).FindControl("SomeControl").ClientID

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
G

Guest

Thank you for the reply. If I try this code

var clientId = <%=
((ImageButtonLink)this.FindControl("imgLinkRead")).FindControl("imageLink").ClientID %>;

ImageButtonLink being the control and imageLink being the hyperlink within
the ImageButtonLink, clientId returns the NavigationUrl. Why would it do
that? Thanks again.
 
K

Kevin Spencer

Hi eric,
var clientId = <%=
((ImageButtonLink)this.FindControl("imgLinkRead")).FindControl("imageLink").ClientID
%>;

ImageButtonLink being the control and imageLink being the hyperlink within
the ImageButtonLink, clientId returns the NavigationUrl. Why would it do
that? Thanks again.

I couldn't say without seeing the actual code.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 

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,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top