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

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top